gnuplot columnhead labels "at end" and in key

1.2k views Asked by At

Two questions about columnheader in gnuplot:

1) I'm plotting a few data columns with column headers and I want to label the graphs BOTH near the end of each graph line (with "at end") AND in a key. If I use "unset key", I get clean labels at the end of the graphs.

unset key
plot for [col=2:6] file using 1:col with lp ls col title columnhead(col) at end

Graph 1

If I comment out "unset key" and try to draw BOTH the labels near the end of each graph AND in the key, I get some weird artifact to the right of the properly drawn key. Any way to get rid of this artifact?

### unset key
plot for [col=2:6] file using 1:col with lp ls col title columnhead(col), for [col=2:6] file using 1:col with lp ls 
col title columnhead(col) at end

Graph 2

2) Sometimes I want a substring of the column header when labeling. I tried "substr" (see below), but I get a "0", instead of the substring. Is there a way to get substring of the column header?

plot for [col=2:6] file using 1:col with lp ls col title substr(columnhead(col),0,1) at end

EDIT: Sample data file:

Date,V,W,D,Y,X
2017-09-03,0,0,0,0,-
2017-09-05,-3.67,-4.71,-2.86,-1.69,-
2017-09-06,-4.19,-6.42,-1.65,-1.86,-
2017-09-07,-2.41,-5.64,1.24,-0.26,0
2017-09-08,4.61,-5.38,1.47,0.45,-2.55

EDIT2: Even this simple script with the data above gives me the artifact (Win7 x64, gnuplot 5.2)

set terminal gif
set output "test.gif"
set datafile separator ","
set timefmt "%Y-%m-%d"
set xdata time
plot for [col=2:6] "test.dat" using 1:col with lp ls  col title columnhead(col) at end
2

There are 2 answers

2
Karl On

Bug in 5.2pl0. It overprints the lines in the legend if the "at end" option is used:

plot for [i=1:5] i+x title "i=".i at end

5.0pl6 doesn't do that. Bug report has been filed on sf.net.

2
user8153 On

(This is really just a comment, but I want to provide an image so post it as an answer instead)

Are you sure it's not something else in your gnuplot script that causes a problem? Using the data you posted,

set datafile separator ","
set timefmt "%Y-%m-%d"
set xdata time
plot for [col=2:6] "test.dat" using 1:col with lp ls  col title columnhead(col) at end

gives

enter image description here

which doesn't show the artifact.