Darby
2020-04-14 20:43:55 UTC
I've run into a problem with controlling the legend when using multiplot. I want the legend to stay in 1 column on the right side of the plot. With just a single plot per page, this works. But if I use multiplot (4 plots per page, layout 2,2), the legend wants to split into multiple columns, even if I try to force it to one column with "maxcols 1". In this case, the legend is too wide and obscures some of the plots. However, a multiple with two tall plots side by side seems to do the right thing. So it seems like this is tied to the size of the plot, not the page. I've recreated this with some simple examples below. I'm using gnuplot 4.6 patchlevel 2 on CentOS 7.7.
set xrange [-pi:pi]
set key at screen 1,1
# ----------
# The legend for a single plot seems to respect the space of the plot
# and only uses 1 column.
set size 0.9,1.0
plot for [i=1:5] 10*sin(i*x) w l t 'sin',\
for [i=1:5] 10*cos(i*x) w l t 'cos',\
for [i=1:5] i*x w l t 'line',\
for [i=1:5] -i*x w l t 'line'
pause -1
# ----------
# The legend for a multiplot seems NOT to respect the space of the plots
# and uses 2 columns, despite the explicit request for one column.
set key maxcols 1
set multiplot layout 2,2 scale 0.8, 1.0
replot
replot
replot
replot
unset multiplot
pause -1
# ----------
# But a "layout 1,2" multiplot will do one column. Is it based on the height of the
# plot?
set multiplot layout 1,2 scale 0.8, 1.0
replot
replot
unset multiplot
pause -1
# ----------
set xrange [-pi:pi]
set key at screen 1,1
# ----------
# The legend for a single plot seems to respect the space of the plot
# and only uses 1 column.
set size 0.9,1.0
plot for [i=1:5] 10*sin(i*x) w l t 'sin',\
for [i=1:5] 10*cos(i*x) w l t 'cos',\
for [i=1:5] i*x w l t 'line',\
for [i=1:5] -i*x w l t 'line'
pause -1
# ----------
# The legend for a multiplot seems NOT to respect the space of the plots
# and uses 2 columns, despite the explicit request for one column.
set key maxcols 1
set multiplot layout 2,2 scale 0.8, 1.0
replot
replot
replot
replot
unset multiplot
pause -1
# ----------
# But a "layout 1,2" multiplot will do one column. Is it based on the height of the
# plot?
set multiplot layout 1,2 scale 0.8, 1.0
replot
replot
unset multiplot
pause -1
# ----------