Search code examples
plotlabelkeygnuplot

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.


Solution

  • 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