I have a mulit-plot that doesn't look pretty, which is supposed to go into a physics paper. Although I am having lots of issues as you can see, the most frustrating is that it seems that Gnuplot is outright disobeying my set ytics commands on some of the subplots. Also, my axis labels for the first plot are ending up on the second plot instead. How do I solve these problems of Gnuplot having a mind of its own and refusing to do what I say?
reset
set terminal postscript eps enhanced color size 10,5
set output 'C:\\Users\\cole1\\Desktop\\multiplot3.eps'
set multiplot
set xtics font "Times-Roman, 20"
set ytics font "Times-Roman, 18"
set size .5,.25
set origin 0,.75
set label "(a)" at screen .06,.95
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\logefficiency1.txt' using 1:2 lc rgbcolor "#FF0000" pt 5 with lp notitle
set ytics -3,1,2
set xlabel "Log_{10} current density factor"
set ylabel "Log_{10} percent efficiency"
unset label 1
set size .5,.25
set origin .5,.75
set label "(b)" at screen .56,.95
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4009.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,0.5,1
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin 0,.5
set label "(c)" at screen .06,.7
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4018.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,1,4
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin .5,.5
set label "(d)" at screen .56,.7
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4027.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,15,60
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin 0,.25
set label "(e)" at screen .06,.45
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4036.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,15,60
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin .5,.25
set label "(f)" at screen .56,.45
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4045.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,15,60
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin 0,0
set label "(g)" at screen .06,.2
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4054.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,30,120
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
set size .5,.25
set origin .5,0
set label "(h)" at screen .56,.2
plot 'C:\\Users\\cole1\\Documents\\MATLAB\\spectralinfo4063.txt' using 1:2 lc rgbcolor "#0000FF" with lines notitle
set ytics 0,300,1200
set xlabel "Frequency(THz)"
set ylabel "Intensity/ freq. interval (arb.)"
unset label 1
unset xtics
unset ytics
unset multiplot
The ytic settings work only if placed before the plot command. That applied to all settings. Everything which must appear in a graph and all the settings must be done before the respective plot command:
set ytics 1
plot x
Here is an improved version of your script:
reset
datadir = 'C:\\Users\\cole1\\Documents\\MATLAB\\'
set terminal postscript eps enhanced color size 10,5
set output 'multiplot3.eps'
set xtics font "Times-Roman, 20"
set ytics font "Times-Roman, 18"
set style line 1 lc rgb "red" pt 5
set style line 2 lc rgb "blue"
set style data lines
unset key
set multiplot layout 4,2
set label 1 "(a)" at graph 0.01,0.9
set ytics 1
set xlabel "Log_{10} current density factor"
set ylabel "Log_{10} percent efficiency"
plot datadir.'logefficiency1.txt' ls 1 with lp
set label 1 "(b)"
set ytics 0.5
set xlabel "Frequency (THz)"
set ylabel "Intensity / freq. interval (arb.)"
plot datadir.'spectralinfo4009.txt' ls 2
set label 1 "(c)"
set ytics 1
plot datadir.'spectralinfo4018.txt' ls 2
set label 1 "(d)"
set ytics 15
plot datadir.'spectralinfo4027.txt' ls 2
set label 1 "(e)"
plot datadir.'spectralinfo4036.txt' ls 2
set label 1 "(f)"
plot datadir.'spectralinfo4045.txt' ls 2
set label 1 "(g)"
set ytics 30
plot datadir.'spectralinfo4054.txt' ls 2
set label 1 "(h)"
set ytics 300
plot datadir.'spectralinfo4063.txt' ls 2
unset multiplot
The main points are:
Use set multiplot layout 4,2 to have the size and the origin changed automatically.
You must set the xlabel and ylabel only once if they don't change.
Likewise you must use set ytics only if the settings change.
Usually, if you have autoscaling enabled, you must not specify start and end of the ytics, but only the increment.
For the subfigure label use coordinates relative to the actual plot (graph 0.01,0.9). And use always the same label id (1). Then for the second and all following plots you must change only the text, the old coordinates are used. Then you can do the fine-tuning of the label position at only one position in the code.
Use set style data lines
Use line styles
Use unset key to hide the legend.
Related
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.1
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
plot sin(x) lc 0
This code displays the problem - different positionning of x/y labels by splot, plot.
Although you have the margins identical for both plots for some reason (which I don't know) the labels are not at identical positions. However, since the label values are identical anyway, no need for trying to plot the second labels on top of the first ones. Simply skip all labels and tics of the second plot.
Code:
### remove shifted tics in multiplot
reset session
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.15
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
unset xlabel
unset ylabel
unset xtics
unset ytics
plot sin(x) lc 0
unset multiplot
### end of code
Result:
It is quite possible that you can create your composite plot entirely with splot and therefore do not need to use multiplot, bypassing the whole issue. I realize that the example you give may be over-simplified but as it stands the plot can be created by
set xrange [-2:2]
set yrange [-2:2]
set trange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set view map
set pm3d at b
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2 with pm3d, \
'+' using 1:(sin($1)):(0) with lines lc "blue" lw 3
With gnuplot 5.2.8, the figure can be created with just one plot command:
pl [-2:2][-2:2] sample [0:2*pi] "+" us (cos(x)):(sin(x)) with filledcurve, sin(x)
Thus splot and multiplot are not needed here.
sample is needed to redefine the parameter range (only in case of first plot argument).
A documentation is here: https://github.com/gnuplot/gnuplot/blob/4a7a11e6b528ea362c943cf632fd21a518b15c54/docs/gnuplot.doc#L7856
PS: As you see it also works without $1 for your cairolatex terminal.
Is it possible to add more then one yrange on the left hand side of the plot using gnuplot?
See the figure linked below, please.
Ideally I would need yrange commands such as y3range, y4range, etc.
Using multiplot I could not get what I want.
set multiplot
set lmargin at scr 0.2
set bmargin at scr 0.1 # fix bottom margin
set grid
set y2range [0:20]
plot x, 2*x axes x1y2 # this is your actual plot
unset grid
set lmargin at scr 0.2
set bmargin at scr 0.15 # fix bottom margin
set yrange [0:20] # set yrange to the same as y2 in the first plot
set border 0 # switch off all borders except the left
unset xtics # switch off the stray xtics
plot -1000 notitle # plot something outside of the y(2)range
unset multi
Thank you for your help.
You have to set the yranges accordingly such that the ytics and hence the grid are nicely aligned.
Add an offset to the ytics to tune the distances. Check help xtics.
Code:
### multiple axes
reset session
# common settings for all (sub-)plots
set lmargin at screen 0.15
set bmargin at screen 0.12
set xlabel "my x-title"
set xrange[0:3000]
set grid
set ytics font ",8"
myOffsetY = 0.7
set multiplot
set ylabel "my 1st y-label" tc rgb "red" offset -2,0
set yrange [-10:6]
set ytics -10,2 tc rgb "red" offset 0,0
plot 0.001*x-10 w l lc rgb "red" notitle
set xlabel " "
unset xtics
unset grid
set ylabel "my 2nd y-label" tc rgb "green" offset 2,0
set yrange [-10.0:-2.0]
set ytics -10, 1 tc rgb "green" offset 0,-myOffsetY
set format y "%.1f"
plot 0.002*x -10w l lc rgb "green" notitle
set ylabel "my 3rd y-label" tc rgb "blue" offset -4,0
set yrange [-60:20]
set ytics -60, 10 tc rgb "blue" offset 0,myOffsetY
set format y "%.0f"
plot 0.003*x-10 w l lc rgb "blue" notitle
unset multiplot
### end of code
Result:
I have two plots in multiplot, on my second plot ticks label is not appearing, which I want to appear at the bottom X-axis
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
set multiplot layout 2,2
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [0:5]
set yrange [200:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
'MAN.outmd' lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,
unset x2label
unset x2tics
unset ylabel
unset ytics
#
set size ratio 0.9
set xlabel
set xtics 5
set ytics 0.5
set xlabel "Period (s)" offset 2.5
set ylabel "Group Velocity (km/s)" offset 2.5
set xrange [15:45]
set yrange [3:4.5]
set label 3 at 30,3.5
set label 4 at 18,4.3
set label 5 at 20,4.0 font "arial-Bold,130"
set key right bottom samplen 0.9
#
set label 3 "C1 (MNAI)" center font "arial-Bold,130"
set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
set label 4 "(a)" center font "arial-Bold,97"
plot 'MANdsp.out' lc rgb 'red' lw 35 title "Model fit dispersion curve",\
'mandsp.in' lc rgb 'blue' lw 35 dt"-" title "Observed dispersion curve" smooth acsplines,
unset multiplot
The ticks are appearing on X-axis, but the ticks X-axis bottom labels are not appearing. I have tried other ways too, but unable to come over it
Regarding xtics, you do the following:
...
set xtics format "" # Don't print x-axis bottom tic labels!!!
...
set x2tics nomirror # Print x2tics, tic labels are included by default.
...
...# First plot # -> You see x2 tic labels.
...
unset x2tics # Don't print x2 tics
...
set xtics 5 # Print x-axis tics, but keep empty tic labels.
...
...# Second plot # -> no x2 tics; xtics are printed without labels.
You can reset the x-axis tic label default format with:
set xtics 5 format "% h"
See help set format for other format options.
So if I take your script and change it with the following steps
replace the two plot commands with plot sin(x), cos(x) because you did not show the data,
replace the set xtics 5 command by set xtics 5 format "% h",
I arrive at this script:
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
set multiplot layout 2,2
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [0:5]
set yrange [200:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
#plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
#'MAN.outmd' lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,
plot sin(x), cos(x)
unset x2label
unset x2tics
unset ylabel
unset ytics
#
set size ratio 0.9
set xlabel
set xtics 5 format "% h"
set ytics 0.5
set xlabel "Period (s)" offset 2.5
set ylabel "Group Velocity (km/s)" offset 2.5
set xrange [15:45]
set yrange [3:4.5]
set label 3 at 30,3.5
set label 4 at 18,4.3
set label 5 at 20,4.0 font "arial-Bold,130"
set key right bottom samplen 0.9
#
set label 3 "C1 (MNAI)" center font "arial-Bold,130"
set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
set label 4 "(a)" center font "arial-Bold,97"
#plot 'MANdsp.out' lc rgb 'red' lw 35 title "Model fit dispersion curve",\
#'mandsp.in' lc rgb 'blue' lw 35 dt"-" title "Observed dispersion curve" smooth acsplines,
plot sin(x), cos(x)
unset multiplot
And I get this picture with x axis tic labels on the right diagram:
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...
I have been trying very unsuccessfully to stack 3 graphs together in a multi-plot layout on a canvas that is a ratio of 2:3(width by height).
set terminal postscript eps enhanced "Helvetica" 24 color
set output "data.eps"
set timefmt "%s"
#set size 1.0,1.5
#set bmargin 2
#set tmargin 2
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set tmargin 2
set bmargin 0
set ylabel 'Distance'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace1.dat" using 1:3 axes x1y1 title "distances" with lines lw 2 lc rgb 'blue'
set size 1.0,0.5
set bmargin 0
set tmargin 0
set ylabel 'Power (W)'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace2.dat" using 1:2 axes x1y1 title "device" with lines lw 2 lc rgb 'red'
set size 1.0,0.5
set bmargin
set tmargin 0
set xdata time
set ylabel 'Power (W)'
set xlabel 'Time (EST)' offset 0,-2.8 font "Helvetica,32
set format x "%b %d, %H:%M"
set ytics nomirror font "Helvetica,10"
set xtics nomirror rotate by 90 offset 0,-2.0 out font "Helvetica,10"
set key top
plot "trace3.dat" using 1:2 axes x1y1 title "aggr" with lines lw 2 lc rgb 'blue'
unset multiplot
When I do something like above, I get the plot shown below, there's a lot of blank space at the top of the canvas and the 3 multiplot graphs seem to overlap each other.
Any kind of help or pointer will be greatly appreciated.
In order to use a bigger canvas, you must use the size option when setting the terminal, e.g.:
set terminal postscript eps enhanced size 10cm,15cm
set size just changes the plot size relative to your canvas. To see this, consider
set terminal wxt
set size 1.0,1.5
plot sin(x)
Parts of the plot disappear, because it is much too high with respect to the canvas.
To stack three plots with same heights, in my opinion its best to use fixed margins:
set terminal pngcairo size 600, 900
set output 'stacking.png'
set lmargin at screen 0.15
set rmargin at screen 0.95
TOP=0.98
DY = 0.29
set multiplot
set offset 0,0,graph 0.05, graph 0.05
set xlabel 'time'
set ylabel 'ylabel 1' offset 1
set tmargin at screen TOP-2*DY
set bmargin at screen TOP-3*DY
set ytics -1000,500,1000
plot 1150*cos(x) title 'First'
set xtics format ''
unset xlabel
set ylabel 'ylabel 2' offset 0
set tmargin at screen TOP-DY
set bmargin at screen TOP-2*DY
set ytics -100,50,100
plot 101*sin(x) title 'Second'
set ylabel 'ylabel 3' offset -1
set tmargin at screen TOP
set bmargin at screen TOP-DY
set ytics -8,4,8
plot 10*sin(2*x) title 'Third'
unset multiplot; set output
The result is (with 4.6.3):
In order to avoid overlapping labels of the ytics, you must change the range where the tics are drawn, e.g. with set ytics -100,50,100, which puts ytics between -100 and 100 in steps of 50. Using set ytics rangelimited doesn't work
To increase the distance between the plot curve and the border, use set offset with graph coordinates, like done in the above script.
I started with the lowest plot, because only that has x labels and an xlabel.
You need to use set origin, too.
set terminal postscript eps enhanced
set output "data.eps"
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set origin 0,1
...
plot ...
set size 1.0,0.5
set origin 0,0.5
...
plot ...
set size 1.0,0.5
set origin 0,0
...
plot ...
unset multiplot