CAF
CAF

Reputation: 339

Add a coloured line to a label in gnuplot?

I was wondering if it is possible to add a coloured line to a label command in gnuplot? That is, say I would like to add a red line after some text in a label command:

set label "some text here which is then followed by a red horizontal line -----" at 100,200 front

Basically, I want to mimic the usual presentation of the key in gnuplot in a label command. I already have one key and another key is not allowed within the same plot environment, so I want to manually construct a second key through the label command.

Thanks in advance.

Upvotes: 2

Views: 790

Answers (3)

theozh
theozh

Reputation: 25694

I would do it the following way. Check the details of help arrow and help label.

Edit: using separate lines and labels is certainly more code but you have full flexibility. I guess it depends on what exactly you want to do.

Code:

### labels with lines
reset session

set size ratio -1

set arrow 1 from 4,0 to 7,0 lc "red" lw 2 nohead
set label 1 at 4,0 "Some text" right offset -1,0

set arrow 2 from 2,-2 to 5,-2 lc "red" lw 2 dt 3 nohead
set label 2 at 5,-2 "Some text" left offset 1,0

set arrow 3 from -6,5 to -2,5 lc "red" lw 2 dt 1 nohead
set label 3 at -4,5 "Some text" center offset 0,-1

set arrow 4 from -6,-2 length 5.5 angle 45 lc "red" lw 2 dt 3 nohead
set label 4 at -6,-2  "Some text" font ",14" right rotate by 45 offset -1,0

plot x w l lc "blue"
### end of code

Result: enter image description here

Upvotes: 1

Ethan
Ethan

Reputation: 15093

You can use a plot clause with the keyword keyentry rather than a file name to generate an extra title and line/point/fill sample for the key. You can also use the keyword at <x-pos>,<y-pos> to place this extra title somewhere else on the page.

Examples from the on-line demo set:

Quick example here:

set xrange [0:20]
plot x**2, x**3, \
     keyentry with lines dt '-' lc "red" title "Extra title" at graph 0.25, graph 0.75 

enter image description here

Upvotes: 1

meuh
meuh

Reputation: 12255

You can have a second key by plotting data that is all invalid (NaN, not a number). For example,

cat >data <<\!
 17  15
 18  5 
 19  10
 21  7   
!
gnuplot -persist <<\!
plot "data" u 1:2 with lines title "plot1", \
 "" u (NaN):(NaN) with lines title "plot2"
!

enter image description here

Upvotes: 1

Related Questions