Gnuplot Version 5.4 patchlevel 1: plot several datasets with single title (legend entry)

Viewed 129

I want to plot several lines. However I want all of them to have the same style and create a single entry in the legend.

When I use

splot '-' with lines

with these data

0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0


0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
e

everything is as I expect. Also as expected, any style is applied to all the lines.

However if I try to add a title

splot '-' with lines title "myTitle"

an entry in the legend for each one is generated.

enter image description here

How can I have a single legend entry?

[Notice that I need two newlines between the data sets, because I want different lines and not a grid] [I am using Gnuplot Version 5.4 patchlevel 1]

Thanks!

3 Answers

Ok, I tested with gnuplot 5.2.6, and there you don't see this behaviour. Pretty, strange. I'm not sure why this has changed. With gnuplot 5.4 you can work around for example with the following. Check help keyentry.

Code:

### only one key for a dataset separated by two empty lines
reset session

$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0


0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD

splot $Data    w l ls 1 notitle, \
      keyentry w l ls 1 title "only one title"
### end of code

Edit: (alternative solution without keyentry and repeating the linestyle)

myTitle(i) = i==0 ? "only one title" : ""
splot for [i=0:*] $Data index i w l ls 1 title myTitle(i)

Result:

enter image description here

Creation of duplicate key entries in this case was an unintended consequence of an intended change. See Issue #2380 duplicate titles in key. For the specific case here where the plot command requests a title by providing a quoted string, the old behavior will be restored in release 5.4.2 - you will only get a single entry in the key even though multiple data sets are plotted.

FYI - the change was introduced because it is now possible to generate a distinct title for each data set in the file. However it is not particularly useful to have multiple titles that are all the same. The intended use is illustrated by

plot 'file.dat' using 1:2 title sprintf("Data set %d", column(-2))

where column(-2) returns the index number of this data set. In earlier gnuplot versions you would have to iterate explicitly over the index number

plot for [index=1:*] 'file.dat' using 1:2 title sprintf("Data set %d",index)

Update showing result in version 5.4.2

### only one key for a dataset separated by two empty lines
reset session

$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0


0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD

set title sprintf("Gnuplot version %.1f.%s", GPVAL_VERSION, GPVAL_PATCHLEVEL)

splot $Data with lines title "myTitle"
### end of code

enter image description here

Related