Only 1 y label in GNUplot multiplot - gnuplot

I use gnu plot to draw a multiplot and in my script I set the y label like that:
set ylabel "foobar"
Now every plot in the multiplot has a dedicated y label on their y axis. However, I would like to have only one y label for all the plots in the multiplot and center that label also on the common y axis. How can I do that? The multiplot layout I use is a 7.1 So all the plots have the same y axis.

The simplest way is to make the first plot, then turn off the y label:
set ylabel 'foo'
set multiplot
plot 'data1.dat'
unset ylabel
plot 'data2.dat'
plot ...
unset multiplot
This will make the x-dimension of the first plot different from that of all the other plots, so you may have to play with the margins if you want all the plots the exact same size.

Plot the individual panels of reduced size without labels but with border, tics and title, then define a full-sized panel with labels but without border, tics and title.You may have to plot a dummy function (1/0).

Global label workaround
This is not ideal, but if you desperate like me, you can use a rotated global label + larger left margins:
#!/usr/bin/env gnuplot
label_label_size = 14
set terminal png
set output "gnuplot.png"
set multiplot layout 2,1 title "Multiplot with one ylabel" font ",18"
set lmargin 10
set label "My y-label" at screen 0.05,0.5 center front rotate \
font "," . label_label_size
plot sin(x)
set xlabel 'My x-label' font "," . label_label_size
plot cos(x)
Here is a realistic application that motivated me to do this: Heap vs Binary Search Tree (BST)
Tested in gnuplot 5.2 patchlevel 6, Ubuntu 19.04.

This is basically the suggestion from Fabian Claremont's answer, but (for beginners) put into code and visualized. Actually, Ciro Santilli's solution is even shorter.
Tested with gnuplot 5.2. For gnuplot 4.6 (the time of OP's question), replace reset session with reset and set margin 8,-1,1-1 with set lmargin 8 and set bmargin 1.
Code:
### Multiplot with single y-label
reset session
unset key
set sample 500
set multiplot layout 7,1
unset ylabel
set linetype 1 lc rgb "red"
set margins 8,-1,1,-1 # left, right, bottom, top (-1=auto)
set ytic 1.0
set title "Plot 1" offset 0,-1
plot sin(1*x)
set title "Plot 2" offset 0,-1
plot sin(2*x)
set title "Plot 3" offset 0,-1
plot sin(3*x)
set title "Plot 4" offset 0,-1
plot sin(4*x)
set title "Plot 5" offset 0,-1
plot sin(5*x)
set title "Plot 6" offset 0,-1
plot sin(6*x)
set title "Plot 7" offset 0,-1
plot sin(7*x)
set lmargin -1 # automatic lmargin
unset title
set origin 0,0
set size 1,1
set border 0
unset tics
set ylabel "This is a centered y-label"
plot [][0:1] -1 # plot a dummy line out of range
unset multiplot
### end of code
Result:

Related

Align ylabel in gnuplot multiplot

Is there a way to align vertically the y labels of in gnuplot's multiplot so that they are below each other? The problematic example is below (the red line is annotation showing the problem):
set xrange[0:10]
set multiplot layout 2,1 margins 0.1,0.95,0.1,0.95 spacing 0,0
set ylabel "y1\nlabel"
set ytics
set format y "%.2f"
plot -1000*cos(x)**2 w l lt 4 lw 2
set ylabel "y2\nlabel"
set format y "%.1f"
plot cos(x) w l lt 5 lw 2
unset multiplot
which generates:
And I would like to automatically position the labels such, that the red annotated line "touches the same text". Note that I am really interested in automatic way or more correct way that a workaround using a trial and error with set ylabel "lable" offset -x,0
As you already noted, you can set an offset to the x- or y-label (check help xlabel), however, no absolute position.
This you can do with setting your own label. You can set the position relative to the screen and/or relative to the graph. gnuplot keeps these values for the second plot, no need to specify again. Check help label.
Check the following example:
Code:
### align ylabels in multiplot
reset session
set xrange[0:10]
set multiplot layout 2,1 margins 0.15,0.95,0.1,0.95 spacing 0,0
set format x ""
unset ylabel
set label 1 "y1\nlabel" at screen 0.02, graph 0.5 center rotate by 90
set ytics 200
set ytics add ("" -1000) # remove -1000
set format y "%.2f"
set grid x,y
plot -1000*cos(x)**2 w l lt 4 lw 2
set format x
set label 1 "y2\nlabel"
set ytics 0.4
set format y "%.1f"
plot cos(x) w l lt 5 lw 2
unset multiplot
### end of code
Result:

How to move and manage overlapping of x ticks with axis in Gnuplot

I am trying to plot an inlet graph which is shown in Figure. Being an inlet graph it is needed to show x tics and y ticks of relatively big sizes for clear visibility. But when I increase the fonts as,
set xtics font ", 40"
tics overlaps with axis. I increased the plot size set term png size 1000, 1000 but still the issue persists. Kindly suggest if there is a way to move the tics below or to a desired position in graph.
Edit:
The gnuplot script looks like this,
set term png size 1000, 1000
set output "b_vs_N.png"
set style fill solid
set style circle radius 0.001
FIT_LIMIT=1.e-14
set yrange [0.15:0.25]
set style fill solid
set style circle radius 0.001
set xtics 10
set ytics 0.03
set border 15 back lw 6
set xtics font ", 40"
set ytics font ", 22"
set ylabel "b" enhanced font "1 {,40}"
set xlabel "N_i" font "1 {,40}"
set lmargin 12
set bmargin 4
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
AA(x)=a+b*x+c*x**2
fit AA(x) "data.txt" using 1:2 via c, b, a
plot "data.txt" using 1:2 lt 1 pt 11 ps 2.0 lc rgb "black" notitle, AA(x) w lines lw 2 lc rgb "sienna1" notitle
Your example is uncomplete without code and therefore difficult to reproduce. Please check help xtics. There is the option offset.
Maybe the following example helps to solve your issue.
In the example below no special offset seems to be necessary, i.e. offset 0,0, but you can shift and adjust the labels in x and y direction.
Code:
### tic label offset
reset session
set multiplot
plot sin(x)/x
set origin 0.07, 0.6
set size 0.3,0.3
set xrange [0:10]
set xtics 5 out font ",20" offset 0,0
plot x**2
unset multiplot
### end of code
Result:

Gnuplot Multiplot Individual Plot Sizes + Labels

I am currently trying to produce a decent multiplot in Gnuplot. Sadly I ran into some problems.
As the y-axis for both figures is the same I want to only label and tic it once, however I cant remove those from only the left plot.
Secondly I want to increase the width of the left plot while decreasing the one of the right.
Here is a picture of what I got so far, the code is below.
Plot so far
set term postscript eps enhanced color "Helvetica" 10
set output "dosband.eps"
set title "Bandstructure and Density of States"
#
set multiplot layout 1,2 \
margins 0.075,0.98,0.1,0.98 \
spacing 0.02,0.08 #margins: left,right,bottom,top; spacing: vertical, horizontal
set title "Bandstructure"
plot 'plotband.dat' using 1:2 with lines lt 1 lw 0.5 linecolor rgb "black" notitle
set xlabel "Density [states/eV]" #dont ask me why I have to swap the xlabels around
set ylabel "Energy [eV]"
#
set title "Density of States"
plot 'plotdos.dat' using 1:2 with lines lt 1 linecolor rgb "black" notitle
set xlabel "K-Points"
unset multiplot
Thanks in advance for any answers!
As noted by #Christoph, using explicit margins is one of the solutions. In your particular case, you could proceed as:
#dimensions are in screen units
width_left = 0.48
width_right = 0.25
eps_v = 0.12
eps_h_left = 0.1
eps_h_right = 0.05
unset key
set multiplot
set tmargin at screen 1. - eps_v
set bmargin at screen eps_v
set lmargin at screen 0.1
set rmargin at screen eps_h_left + width_left
set xr [0:1.4]
set xtics 0,0.2,1.4
set yr [-40:5]
unset ytics
set y2r [-40:5]
set y2tics in mirror
set format y2 "" #draw ticks but no tic labels
set title "Plot 1"
set xlabel "title 1"
plot 1/0
set lmargin at screen 1. - (width_right + eps_h_right)
set rmargin at screen 1. - eps_h_right
set xr [0:100]
set xtics 0,25,100
unset y2tics
set yr [-40:5]
set ytics in mirror
set mytics 1
set title "Plot 2"
set xlabel "title 2"
set ylabel "Energy [eV]"
plot 1/0
This produces:
In case the Energy [eV] label is supposed to be moved completely to the left, one can adjust the spacings/tics accordingly...

Adjusting position of individual plots in gnuplot multiplot

I am using multiplot to plot four graphs. My code is given below
set term postscript eps enhanced color
set pm3d map
set pm3d corners2color c1
set size square
set out 'defect2.eps'
unset colorbox
set colorbox horiz user origin 0.1,0.7 size 0.8,0.02
set cbrange [-1.6:0]
set xtics 25
set ytics 25
set lmargin at screen 0.1
set rmargin at screen 0.9
set multiplot layout 1,4
set xlabel "i" font "Times-italic,20"
set ylabel "j" font "Times-italic,20"
spl 'defect.dat' notitle
unset ylabel
spl 'defect_2.dat' notitle
spl 'defect_3.dat' notitle
spl 'defect_4.dat' notitle
unset multiplot
set out
This produces a following plot
However, individual plots in the picture are not properly placed. I cannot see ylabel for the first plot as it is hidden behind the screen whereas there are large blank gaps between those plots. Is there any way to reduce these gaps, increase size of these plots and show the labels properly?
Thanks in advance.
The Problem is your margin setting. The margin defines the size of the white stripe between the box containing the plot and the border of the window.
This means, tic and axis labels are printet on the Martin area! And your 10% of window width is not enough, so the labels are clipped.
So you can adjust the margins to shift all plots more to the left or adjust label font sites and offsets (Miguel's comment).

Gnuplot, Multiplot: Mix normal and parametric plot with a single legend box?

I create overlapping graphs in Gnuplot, because I mix normal and parametric plots (and also pm3d maps and parametric surfaces). This works fine mostly, except for one thing: If both plots have a title, the legends usually overlaps. A typical example looks like this:
#legends.gp
set term pngcairo enhanced color linewidth 1.5 dashed dashlength 1.4 rounded
set output "legends.png"
set title "legends test"
set multiplot
# make a box around the legend
set key box
set border 15 lw 1
# fix the margins, this is important to ensure alignment of the plots.
set lmargin at screen 0.15
set rmargin at screen 0.98
set tmargin at screen 0.90
set bmargin at screen 0.15
set xlabel "x"
set ylabel "sin(x)"
set xrange[0:2*pi]
set yrange[-1:1]
set grid x y
# add single tic at 0.62
set xtics add ("x0" 0.62)
# main plot command
plot sin(x) title "sinus"
# turn everything off
set format x "" #numbers off
set format y ""
set xlabel "" #label off
set ylabel ""
set border 0 #border off
unset xtics #tics off
unset ytics
unset grid #grid off
unset title #title off
#plot vertical line at 0.62
set parametric
plot 0.62,t ls 2 lw 2 title "parametric Line"
unset parametric
unset multiplot
My question is now, is there a simple, mostly automatic way to create a single legend for multiple plots?
P.S. Sorry, I ended up making the example file more complex than it had to be by showing some more features, that are hopefully helpful for future readers.
Here's a VERY dirty hack that works for me. change:
plot sin(x) title "sinus"
to:
plot sin(x) title "sinus",NaN w l ls 2 lt 2 title "parametric line"
Then plot the parametric line without a title (e.g. notitle instead of title "parametric line").
This works because gnuplot ignores NaN's when plotting -- Essentially the second thing we're plotting above just adds one element to the legend. I specify the linetype, etc to be the same as your parametric plot linestyle/type so that it shows up properly in the legend. To my knowledge, this is the only way to do something like this...
Of course, you could just edit it so that both are plotted parametrically and forgo the entire multiplot buisness...
set xrange [0:2*pi]
set yrange [-1:1]
set parametric
set trange [-10:10]
plot t,sin(t) title "Hello", 0.62,t title "World"
that's probably the "cleaner" solution...(but less fun working with gnuplot "magic")
From the gnuplot info manual:
To draw a vertical line from the bottom to the top of the graph at
x=3, use:
set arrow from 3, graph 0 to 3, graph 1 nohead

Resources