Set textcolor variable and dot color with label type in gnuplot

Associated with how to set the label and align the same color in gnuplot - but not quite the same ... Using this code:

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine" set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue" set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral" set xrange [0:3] set yrange [0:3] # function to get style index for coloring: getCol(x) = (x==0)?1:((x==1)?2:3); plot \ '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \ lc variable notitle, \ "" using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \ textcolor variable point linestyle 1 pointtype 7 lc variable \ font ",6" offset character 1.0,character 1.0 notitle 0 0 1 1 1.5 1 2 2 e 0 0 1 1 1.5 1 2 2 e 

... I get this output:

gnuplot-out

Everything seems to be great for impulses coloring - however, for labels , it seems to work, but as if the colors are being read from another index ?!

So, how do I get dots and labels to have the same variable color using the same function - like impulse lines? This is on gnuplot 4.6 patchlevel 1 ...

+4
source share
1 answer

The color index for impulses used to select the line style, whereas for labels line type is used. This behavior is still present in the current development version. According to the documentation, the behavior for labels correct. help linecolor variable says: " lc variable tells the program to use the value read from one input column as a line type index ... You can set the text color in the same way with tc variable ." Error, function or incorrect documentation?

As a workaround, you can use lc palette and an appropriately defined palette :

 set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine" set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue" set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral" set palette defined (1 "aquamarine", 2 "blue", 3 "coral") unset colorbox set xrange [0:3] set yrange [0:3] # function to get style index for coloring: getCol(x) = (x==0)?1:((x==1)?2:3) unset key plot \ '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses lc variable, \ '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \ tc palette point ls 1 pt 7 lc palette offset 1,1 0 0 1 1 1.5 1 2 2 e 0 0 1 1 1.5 1 2 2 e 

This gives the result: enter image description here

I hope the workaround works in your real case too. If for some reason you cannot override the palette, you can use lc rgb variable , in which case the last column should be an integer representation of the corresponding rgb color:

 set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine" set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue" set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral" set xrange [0:3] set yrange [0:3] rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b) rgb1 = rgb(2, 215, 245) # something like aquamarine rgb2 = rgb(0, 0, 255) rgb3 = rgb(245,140,2) getCol(x) = (x==0)?rgb1:((x==1)?rgb2:rgb3) unset key plot \ '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \ lc rgb variable, \ '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \ tc rgb variable point ls 1 pt 7 lc rgb variable offset 1,1 0 0 1 1 1.5 1 2 2 e 0 0 1 1 1.5 1 2 2 e 

You may only need tweek rgb values.

However, I will talk about this discussion on the gnuplot mailing list to see if this is really a bug or something else.

+3
source

Source: https://habr.com/ru/post/1498274/


All Articles