Reputation: 249
I have four curves to plot. The first three are variants of each other, the fourth one is distinct. Hence, I would like the key to split in 3+1. However, using e.g.
set key maxrows 3
plot sin(x),sin(2*x),sin(3*x),exp(x)
gives a two-row key.
Can I force gnuplot to split the key in three+one?
Upvotes: 1
Views: 1420
Reputation: 25704
In addition to @user8153's solution, I would like to suggest a slightly more general solution.
What if you have a colored background? For example: set term wxt background rgb "grey90"
or if
you have a colored key (or legend) box... hmm, well, gnuplot doesn't offer an option for
colored background of the key box. Well, then if you put a colored rectangle behind the key.
Of course you can always adapt the color to the background, but I guess it would be simpler to plot an invisible line with lt -2
or lt nodraw
.
About lt -2
or lt nodraw
, I just learned a few days ago here: gnuplot: why is linewidth 0 not zero in width?. It's not (yet) in the manual, although it seems to be around since gnuplot version 5.0.
Script: (works for gnuplot>=4.6.7)
### invisible keyentry for column/row arrangement
reset
set key top left maxrows 3
set obj 1 rect from graph 0.02,0.82 to graph 0.52,0.98 fs solid 1.0 fc rgb "grey90"
set xrange[-2:2]
set yrange[-2:2]
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lt -2 ti " "
### end of script
Result:
Addition:
Actually, I forgot that there is a workaround for a colored background of the keybox. No manual adjustment and fiddling around with the box: Set custom background color for key in Gnuplot
Update: as of gnuplot 5.4.4 there is an option for a colored background of the key box (check help key
)
In case you want a transparent background, e.g. for images on webpages using, e.g. pngcairo, pdfcairo, etc., besides lt -2
or lt nodraw
, another solution would be to plot a transparent line, e.g. transparent "black" lc rgb 0xff000000
:
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lc rgb 0xff000000 ti " "
Script:
### invisible keyentry for column/row arrangement with transparent background
reset session
set term pngcairo transparent
set output "SO51358774.png"
set key top left maxrows 3
set xrange[-2:2]
set yrange[-2:2]
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lt -2 ti " "
set output
### end of script
Result: (shown in front of checkerboard pattern)
Upvotes: 2