Multiplot in GNU Plot with pm3d - gnuplot

I have an issue with multiplot in pm3d. I have a script which plots one surface but when I set multiplot, it says xrange is out of range:
Here is my code:
set terminal png size 2000,1600 enhanced transparent
set encoding utf8 #iso_8859_1
set output 'output.png'
#---------------#
# Canvas style #
#---------------#
set border linewidth 2
set pm3d border lw 2
#-------------------------------------------#
# Set the Axis and Axis-Labels Formatting #
#-------------------------------------------#
### Set xtics below ###
set xtics font "Helvetica,26" scale 3 # Font for xtics
set xtics offset 3,-1.5 # Put xtics away from the axis
### Set ytics below ###
set ytics font "Helvetica,26" scale 3
set ytics offset 3,0 # Put ytics away from the axis
### Set ztics below ###
set ztics font "Helvetica,26" scale 3
set ztics 5 # Difference between numbers on Y-axis
set format z "" # To hide ztics on the left side
set grid # Show gridlines on both axis
set pm3d interpolate 3,3 # Lines on points. Smoothness of the points
unset key # Show no key
#------------------#
# Plot the Graph #
#------------------#
splot "plastoquinone-scan-a1-formatted.txt" with pm3d
#----------------#
# Set Multiplot #
#----------------#
#set multiplot layout 2,2
#plot "++" "plastoquinone-scan-a1-formatted.txt" with pm3d
#plot "++" "plastoquinone-scan-a2-formatted.txt" with pm3d
The data files are quite long so I uploaded them on github.
Here are the links please:
https://github.com/i4hashmi/Scans/blob/master/plastoquinone-scan-a1-formatted.txt
https://github.com/i4hashmi/Scans/blob/master/plastoquinone-scan-a2-formatted.txt
I need these graphs for my PhD thesis. Help will be appreciated a lot.
Thanks

Related

GNUplot stacked multiplot - Top plot does not align perfectly

I'm trying to make a stacked plot with GNUplot.
TMARGIN = 0.05
BMARGIN = 0.15
LMARGIN = 0.15
RMARGIN = 0.0
TCOORD=1-TMARGIN
BCOORD=1-BMARGIN
DY = 0.2
# Ratio
set size ratio 0.5
# Tics
unset xtics
unset ytics
# Multiplot
set multiplot layout 4, 1
unset key
unset title
# Global
set lmargin at screen LMARGIN
set rmargin at screen RMARGIN
# Plot 0
set tmargin at screen TCOORD; set bmargin at screen TCOORD-DY;
plot sin(x)
# Plot 1
set tmargin at screen TCOORD-DY; set bmargin at screen TCOORD-(2*DY)
plot sin(x)
# Plot 2
set tmargin at screen TCOORD-(2*DY); set bmargin at screen TCOORD-(3*DY)
plot sin(x)
# Plot 3
set tmargin at screen TCOORD-(3*DY); set bmargin at screen TCOORD-(4*DY)
set xlabel "xlabel"
plot sin(x)
With the script above I end up with the top plot not aligned to the others.
Out of ideas.
Grateful for any help.
Thanks in advance!
Edit: This is "Version 5.4 patchlevel 2" on Archlinux if relevant.
Your script tries to use three different methods to adjust the plot positions: set ratio, set multiplot layout, and set margin. They are fighting each other. If I understand the intent correctly, this can all be done in the multiplot layout command. If the 2:1 ratio is important, you may have to calculate the right margin manually and/or adjust the width of the output using the size parameter of set term.
# No extra stuff around the edges
unset xtics
unset ytics
unset key
unset title
# Multiplot
set multiplot layout 4, 1 margins screen 0.15, 1.0, 0.1, 1.0 spacing 0,0
# Plot 0
plot sin(x)
# Plot 1
plot sin(x)
# Plot 2
plot sin(x)
# Plot 3
set xlabel "xlabel"
plot sin(x)
unset multi

I'm trying to use multiplot to combine plot and splot but x,y labels seem to be shifted

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.

Four graphs in one picture

What is wrong please with this graph? I would like to plot four graph in one picture. It displays two graphs. I would like to have one legends with 3 titles, because there are three color used. Then I don't know how to write two titles - one for graphs in left and one for graphs in right.
I would like to have 4 differents plot 2x2 - I have 4 plot in script. I there is lots of mistake.
set tics out nomirror
set encoding iso_8859_1
unset xtics
set ylabel "{/:Italic F} [a. u.]" font "Segoe UI,12" offset 2,0
set ytics nomirror font "Segoe UI,12"
set lmargin screen 0.2 #levý prostor vedle graf
set rmargin screen 0.9 #pravý prostor vedle grafu
set multiplot layout 2,2
set bmargin screen 0.40
set key Left reverse out horiz
set format y "%.2f"
set key tc variable
set xrange [4272:4500]
set yrange [0.7:1.02]
set title "Title 1" font "Segoe UI,12"
set title "Title 2" font "Segoe UI,12"
plot \
x title "Fitted" with lines linecolor rgb "red" lw 1.5,\
x title "Measured" with lines linecolor rgb "black" lw 1.5
unset ytics
set y2tics
set link y2
unset ylabel
set y2label "{/:Italic F} [a. u.]" font "Segoe UI,12" offset 1,0
set tmargin screen 0.4 #posun horní čáry dolního graf
set bmargin screen 0.15 #posun dolní čáry dolního graf
unset key
set tics out nomirror
set xlabel "{/:Italic {/Symbol l}} ({\305})" font "Segoe UI,12"
set xrange [4272:4500]
set yrange [-0.05:0.03]
plot x title "Measured - fitted" with lines linecolor rgb "navy" lw 1.5
set margin
set margin
plot \
x title "Fitted" with lines linecolor rgb "red" lw 1.5,\
x title "Measured" with lines linecolor rgb "black" lw 1.5
set margin
set margin
plot x title "Measured - fitted" with lines linecolor rgb "navy" lw 1.5
I suggest you have a look at plots in the gnuplot online demo collection, in particular this one: custom_key.dem
That demo illustrates automatic placement of separate plots into a grid via the set multiplot layout command, and also illustrates construction of a single legend holding titles and information from the constituent plots. The online copy includes a copy of the commands that generated the plot. If you have trouble adapting that example to your own data, come back and show what you have tried so that people can make further suggestions.
I could see that you used some symbols from symbol font.
If you want, use set encoding utf8 option and write symbols is directly.
You could set font as a terminal option also.
For example: set terminal pngcairo size 800,600 font "Segoe UI,8" enhanced.
To help you to understand as margins screen works, take a look on this figure.
This grid divides the screen (size 800,600 on terminal command) each 10% (0.1 screen unit).
In order to have graphs with the same size and align them each other we have to set the margins of the individual graphs manually.
To make it more easy I used macros commands.
Below a complete example of how to create a 2×2 graph using the multiplot.
reset
set encoding utf8 # Encoding
set terminal pngcairo size 800,600 font "Segoe UI,8" enhanced # Terminal settings
set output "multiplot_2x2.png" # Output file name
set grid ls -1 lc "gray" # grid lines
set tics out nomirror # tics marks
# Line styles
set style line 1 lc "#e41a1c" # red
set style line 2 lc "#377eb8" # blue
set style line 3 lc "#4daf4a" # green
set style line 4 lc "#984ea3" # purple
# Margins for each row and column
Row1 = "set tmargin screen 0.90; set bmargin screen 0.56" # Top and bottom margins
Row2 = "set tmargin screen 0.42; set bmargin screen 0.08"
Col1 = "set lmargin screen 0.08; set rmargin screen 0.48" # Left and right margins
Col2 = "set lmargin screen 0.57; set rmargin screen 0.97"
# Multiplot option with main title
set multiplot layout 2,2 rowsfirst title "{/:Bold=12 Multiplot 2×2}"
# -------------------------------------------------------------------
#Row1; #Col1 # Calling the macros
set title "{/:Bold=10 Row 1, Col 1}" # Title for plot
set xrange [-10:10] # x-range
set yrange [0:50] # y-range
set xtics 2 # Increment for x-tics
set ytics 10 # Increment for y-tics
set xlabel "Crazy distance / Å" # x-label
set ylabel "Crazy values / a.u." # y-label
plot x**2 w l ls 1 title "x^{2}" # The plot
# -------------------------------------------------------------------
#Row1; #Col2
set title "{/:Bold=10 Row 1, Col 2}"
set xrange [-15:20]
set yrange [-4000:8000]
set xtics 5
set ytics 2000
set xlabel "Crazy temperature / °C"
set ylabel "Crazy pressure / Pa"
plot x**3 w l ls 2 title "x^{3}"
# -------------------------------------------------------------------
#Row2; #Col1
set title "{/:Bold=10 Row 2, Col 1}"
set xrange [-15:15]
set yrange [-0.4:1.2]
set xtics 5
set ytics 0.2
set xlabel "Crazy energy / kJ"
set ylabel "Crazy volume / m^{3}"
plot sin(x)/x w l ls 3
# -------------------------------------------------------------------
#Row2; #Col2
set title "{/:Bold=10 Row 2, Col 2}"
set xrange [0:14]
set yrange [-10:15]
set xtics 2
set ytics 5
set xlabel "Crazy value {/:Italic N}_{A} / 10^{23}"
set ylabel "Crazy property / cd sr kg^{−1} m^{−2} s^{3}"
plot cos(x)*x w l ls 4
# -------------------------------------------------------------------
unset multiplot
The result:
Exactly the same result can be achieved using approach on #Ethan's answer, with the advantage dismiss macros use, just write:
set multiplot \
layout 2,2 rowsfirst \
title "{/:Bold=12 Multiplot 2×2}" \
margins screen 0.08,0.97,0.08,0.90 \
spacing screen 0.09,0.14

gnuplot pm3d - Font size control for axis in multiplots

I posted a question previously about plotting multiple 3D surfaces together as a multiplot. I got the solution for that but now I am having issue with controlling the fonts of the graphs.
The fonts are terrible in multiplot and My settings are not doing anything with them
I don't know how to control these fonts. I tried ztics but it does not change anything
Here is my code:
set terminal png size 2000,1600 enhanced transparent
set encoding utf8 #iso_8859_1
set output 'output.png'
set border linewidth 2
set pm3d border lw 2
####Set the Axis and Axis-Labels Formatting####
set format '%g'
set xtics font "Helvetica,26" scale 3 # Font for xtics
set xtics offset 3,-1.5 # Put xtics away from the axis
set ytics font "Helvetica,26" scale 3
set ytics offset 3,0 # Put ytics away from the axis
set ztics font "Helvetica,26" scale 3
set ztics 5 # Difference between numbers on Y-axis
set format z "" # To hide ztics on the left side
set grid # Show gridlines on both axis
set pm3d interpolate 1,1
unset key
###---Plot the Graph###---
splot "plastoquinone-scan-a3-formatted.txt" with pm3d # For a single plot
#----------------#
# Set Multiplot #
#----------------#
#set multiplot layout 3,3
#splot "plastoquinone-scan-a1-formatted.txt" with pm3d
#splot "plastoquinone-scan-a3-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b1-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b2-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b3-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c1-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c2-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c3-formatted.txt" with pm3d
Please suggest how can I control the settings for fonts in multiplot and how can I control the fonts of the "key" appearing on the right side (circled red in figure).
I am unable to insert the links of the input files due to less reputation :(
Thanks for your help.

multiplot - stacking 3 graphs on a larger canvas

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

Resources