Can I force a legend entry, even for dataless series? - gnuplot

My Gnuplot 4.4 is plotting data from N files, each of which has an unknown number of NaNs (which won't be plotted). I've used the following "trick" to make all of the data appear to be part of the same data series:
plot "fileA.dat" using 1:2 linecolor rgbcolor #FF0000 title 'My data', \
"fileB.dat" using 1:2 linecolor rgbcolor #FF0000, \
"fileC.dat" using 1:2 linecolor rgbcolor #FF0000
Notice that the colours are the same, and the title is only given for the first file.
But, if fileA.dat has only NaNs (or for any other reason does not contain plottable information), the series is omitted and I don't get a title at all.
Can I make fileA.dat's legend entry show up regardless, or is there perhaps a better approach to "sharing" legend entries across series? Assume that I do not have any more information than already declared here, before invoking plot.

You can set the title on an "invisible function" like this:
plot "fileA.dat" using 1:2 linecolor rgbcolor "#FF0000" notitle, \
"fileB.dat" using 1:2 linecolor rgbcolor "#FF0000" notitle, \
"fileC.dat" using 1:2 linecolor rgbcolor "#FF0000" notitle, \
NaN linecolor rgbcolor "#FF0000" title "My data"
The linestyle of the explicit "NaN" can also be modified.

Related

How to put a rectangle in the key with same hue as a shaded area in Gnuplot?

I have some shaded area in a plot and I'd like to label that shaded area with a small rectangle of the same hue as the shading in the plot.
I'm using gnuplot - my shading in the plot is achieved with
plot 'XXXX.dat' u 1:($2+$3):($2-$3) w filledcurve ls 999 fs solid 0.2 notitle,\
and I'd like to label the shading area in the key with a small rectangle of the same hue.
Is it possible? I'm also happy to set it manually via
set object rectangle from x1,y1 to x2,y2 fc rgb "blue"
but in this way I've only managed to sample colours from the standard gnu plot palette and not the hue I've set for the shading via fs solid 0.2.
Thanks!
I'm not sure if I understand your problem.
If you want the filled area in your key you have to define a keyentry via title but you are using notitle.
Code:
set key out
plot '+' u 1:($1**2) w filledcurves ls 999 fs solid 0.2 title "filled area"
Result:
If theozh's answer does not apply, e.g. if you want a key entry with a color that is not the entire plot, then current gnuplot (version 5.2.6 or newer) offers a special plot component keyentry that produces a title and sample for any plot style without actually plotting anything. Example:
set key title "Key made with explicit \n{/:Italic keyentry} elements"
plot keyentry with points pt 'ΒΆ' title "points", \
keyentry with lp title "lp", \
keyentry with yerrorbars title "yerrorbars", \
keyentry with xyerrorlines title "xyerrorlines", \
keyentry with circles fs solid fc "dark-red" title "circles", \
keyentry with ellipses title "ellipses", \
sin(x)/x lc "grey" dt '.-' lw 3 title "normal plot", \
keyentry with boxerrorbars title "boxerrorbars", \
keyentry with boxplot fs pattern 1 title "boxplot", \
keyentry with labels point pt 4 title "labels", \
keyentry with vectors title "vectors"

Change the color of the points in labelled plot

The script works, without any change in color, however:
plot '_numXY' using 2:3:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 notitle lc rgb "blue"
The points are black. I want to see the points in blue color.
Why does lc rgb "blue" not work?
The lc settings are ignored for the labels plotting style if they don't follow immediately the point option. In your case you must only place the notitle at the end.
plot '_numXY' using 2:3:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 lc rgb "blue" notitle
As a demonstration example:
set samples 11
set xrange [0:10]
plot '+' using 1:1:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 lc rgb "blue" notitle
The result with 4.6.5 is:

Stacked and grouped bar histogram with Gnuplot

I would like to reproduce a bar chart like this one, i.e.: multiple groups, every group has many bars (4 bars in my case), each bar is segmented in a few slices (two slices in my case).
In my case, I have four algorithms applied on vectors of different sizes (2^0 to 2^20). Each algorithm has two "sections", local computation and communication. For each vector size I want to show the time required by each algorithm to perform the local computation and the communication, along with the total time corresponding to the sum of these two sections.
As a result, I would like to have a group for every vector size. In each group there are four bars corresponding to the four algorithms and each bar is segmented in a (e.g.) red part corresponding to the local computation and a blue part corresponding to the communication.
Is this feasible with gnuplot? I can provide data in whatever format is useful.
Many thanks in advance.
For your data set it doesn't make sense to stack the local and comm parts, because the comm part is to small to see it in the graph. In any case it would also be quite tricky to combine stacked and clustered, depending on the further requirements (legend entries, tick labels etc).
Here is an example of how to plot a clustered histogram for your data set:
set style histogram clustered gap 1
set style data histogram
set style fill solid 1.0 noborder
set termoption enhanced
set xtics out nomirror
myxtic(x) = sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5)))
plot 'test.dat' using ($2+$3):xtic(myxtic(stringcolumn(1))) title 'Algorithm 1',\
for [i=2:4] '' using (column(2*i)+column(2*i+1)) title sprintf('Algorithm %d', i)
The result is:
To group by algorithm, you can create new groups with the newhistogram keyword:
set style histogram rowstacked title offset 4,1
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set xtics rotate by 90 right
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(1) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(1) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(1) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(1) notitle, \
'' using 9 notitle
The local and comm dat are stacked, but the comm part is so small, that you cannot see it in the graph (only when you zoom in).
For the output I used 4.6.3 and the following settings:
set terminal pngcairo size 1000,400
set output 'test.png'
set xtics font ',6'
The result is:
A bit more sophisticated display of the xtics requires some tricking, because for histograms the xtics aren't treated as being numerical, but rather strings. Here is an example:
set terminal pngcairo size 1000,400
set output 'test.png'
set style histogram rowstacked title offset 0,-0.5
set bmargin 3
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set termoption enhanced
set xtics out nomirror
myxtic(x) = (int(floor(log(x)/log(2) + 0.5)) % 5 == 0) ? sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5))) : ""
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(myxtic(real(stringcolumn(1)))) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 9 notitle
With the result

Multiple colorbars in gnuplot

I'm trying to plot two data series in the same graph with multiplot. I would like each of the two data series to be plotted with a different palette. So far I've been trying with multiplot,
set multiplot layout 1,1
#
set palette rgb 21,22,23
splot "S1" using ($1):($2):($3):($5) with points pt 7 ps 3 palette notitle, \
"S1" using ($1):($2):($3):($5) with impulses linecolor "black" notitle
#
set palette rgb 23,28,3
splot "S1" using ($1):($2):($3):($5) with points pt 7 ps 3 palette notitle, \
"S2" using ($1):($2):($3):($5) with impulses linecolor "black" notitle
#
unset multiplot
however, I can not visualize in the X11 terminal the two series at the same time.
Any idea?

gnuplot - removing line title

I tried searching, but I couldn't find the solution for this particular condition. In my plot , I am comparing two traces. I am using a line graph and both traces are plotted with different colors.
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, \
"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", \
"normal2.dat" using 1:2 title 'Without CloneScale' with lines lc rgb "black"
Using this plot command, I get 3 titles in legends and 2 are repeating ones. I just want 2 titles to appear and remove the repeating one. Is it possible to do this?
To accomplish this you should use the notitle tag.
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, "normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", "normal2.dat" using 1:2 with lines lc rgb "black" notitle
or a more general example;
plot 'File.dat' using 1:2 notitle
an alternative that is equivalent to notitle is to set the title to a zero character string;
plot 'File.dat' using 1:2 title ""
If you had more untitled lines than titled lines, it's more convenient to disable titles by default using set key noautotitle:
set key noautotitle
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, \
"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", \
"normal2.dat" using 1:2 with lines lc rgb "black"
If you are not above a bit of trickery:
Just omitting the last "Without CloneScale" title will remove both title and line from the legend.
Setting the last title to a space will show the line and (seemingly) nothing before it in the legend:
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines,"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", "normal2.dat" using 1:2 title ' ' with lines lc rgb "black"

Resources