0
votes

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
Could you post your data file and the complete gnuplot script? I don't think you have to plot every line twice: if you use title ... at end the title will appear both at the end of the line and in the legend. - user8153
I edited OP to add a sample data file. The gnuplot script is a bit too long to post. If I use "title ... at end" WITHOUT "unset key" I get labels at the end, NO proper key, and that strange artifact, by itself, in the bottom left. I do the plotting twice to get a properly drawn key. - MrSparkly
Perhaps you want to split off your second question into a new post. - Karl
Forget it, the second issue is another bug. Report is also on sf.net now. - Karl
Thanks for the bug report. As far as treating the columnhead(col) as a string and manipulating it when plotting: "substr(columnhead(col),0,1)" doesn't work for me, (columnhead(col))[0:1] doesn't work, word(columnhead(col),1) doesn't work (I get "0"), but sprintf("%s",columnhead(col)) does work. - MrSparkly

2 Answers

2
votes

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.

1
votes

(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.