Multiplot stacked over each other vertically, with same x axis in gnuplot - plot

Following is the code I use and below that is my output. I want to remove all the spaces in between my subplots and the x labels. A sample of what I need is provided in the link at the end the only difference being I need all the boxes to be of same size.
set terminal jpeg
set output "mul.jpeg"
set multiplot
set xr[0:10]
set ylabel "y"
set format y ""
set key off
set size 1,0.25
set origin 0.0,0.0;
set xlabel "x"
plot sin(x)
replot sin(2*x)
set origin 0.0,0.25;
set format x ""
plot cos(x)
replot cos(2*x)
set origin 0.0,0.50;
set format x ""
plot sin(x)
set origin 0.0,0.75;
set format x ""
plot cos(x)
unset multiplot
What I actually need is something like this:
https://inspirehep.net/record/1345236/files/hada_fig2.png
Thank you for any help!

From gnuplot 5.0, you can use the solution offered by #Raphael_Roth of setting margins to zero, but should also use the margins option of multiplot, to allow space for the tic labels and xlabel at the bottom.
E.g,
set tmargin 0
set bmargin 0
set lmargin 1
set rmargin 1
set multiplot layout 4,1 margins 0.05,0.95,.1,.99 spacing 0,0
set xrange [0:10]
unset xtics
plot sin(x), sin(2*x)
plot cos(x), cos(2*x)
plot sin(x)
set xtics
plot cos(x)
unset multiplot

One way is to use multiplot layout, but it's a hassle to get it nice with the labels and tics (as they overlapp or don't fit into the canvas)
set terminal jpeg
set output "mul.jpeg"
set tmargin 0
set bmargin 0
set lmargin 1
set rmargin 1
unset xtics
unset ytics
set multiplot layout 4,1
set xr[0:10]
plot sin(x), sin(2*x)
plot cos(x), cos(2*x)
plot sin(x)
plot cos(x)
unset multiplot
The other possibility is to set the margins and/or origin of each plot separately as explained in these SO answers: multiplot - stacking 3 graphs on a larger canvas and How do gnuplot margins work in multiplot mode?

Related

Reducing number of labels on axes in gnuplot

I have generated the code in gnuplot:
set key box bottom right width 2 height 1
set format x "10^{%L}"
set format y "10^{%L}"
set xrange [10**(-4):10**12]
set xtics 10**1
set yrange [10**8:10**31]
set ytics 10**1
set ylabel 'Pressure erg cm^{-3}' font 'Times-Italic,14'
set xlabel 'Density g cm^{-3}' font 'Times-Italic,14'
set logscale x
set logscale y
plot '10.dat' u 1:2 with lines title 'T=1e10',\
'9.dat' u 1:2 with lines title 'T=1e9',\
'8.dat' u 1:2 with lines title 'T=1e8',\
'7.dat' u 1:2 with lines title 'T=1e7',\
'6.dat' u 1:2 with lines title 'T=1e6',\
'5.dat' u 1:2 with lines title 'T=1e5'
to produce such a graph:
But, I would like to reduce the number of labels on x and y axis so I can get sth like this:
Are there some simple ways to do that?
Well, you are explicitly setting the tic distances to 10. In the gnuplot console type help xtics.
Try the following:
set xrange [1e-4:1e12]
set xtics 1e-3, 100
set yrange [1e8:1e31]
set ytics 1e9, 1000
Addition:
Check help xtics. You can place the tics "semi-automatically".
Code:
### "semi-automatic" tics
reset session
set xrange[1e-4:1e12]
set logscale x
set format x ""
set xtics 10
set yrange[1e8:1e31]
set logscale y
set format y ""
set ytics 10
do for [i=-3:12:2] {
set xtics add (sprintf("10^{%d}",i) 10**i)
}
do for [i=9:30:3] {
set ytics add (sprintf("10^{%d}",i) 10**i)
}
plot 1e12*x
### end of code
Result:

Add an aditional space to xrange and yrange

I want to plot multiple files using a Gnuplot script.
However, I'm having some trouble to make it perfect.
My actual plots are something like that:
However, the linepoints plot is touching both the x-axis and the y-axis.
Therefore, I want to add extra space on xrange and yrange and get
which does not touch my axis.
I could to it manually using set xrange and set yrange.
However, I need to plot more than 100 different files, and it will be very time-consuming to do so.
There is some manner to automatically increase the size of xrange and yrange by some units?
My Gnuplot code is below.
#!/usr/bin/env gnuplot
set terminal epslatex size 7.5,3 standalone
set output 'pareto.tex'
set style fill solid 0.8
set ytics nomirror
set xtics nomirror
set grid lc rgb "#F2F2F2"
set xlabel 'Z_1'
set ylabel 'Z_2'
set xrange [170:215]
set yrange [7:40]
set style line 1 lt rgb "#000000" lw 12 pt 7 pointsize 3
plot "../exact.dat" using 1:2 title '$aug\,\epsilon$-CM' with linespoints ls 1
unset output
set output # finish the current output file
system('pdflatex --interaction=batchmode pareto.tex')
unset terminal
system
The command you are looking for is set offset. See the documentation for a full description.
Example:
set multiplot layout 3,1
# Default placement
plot 'silver.dat' with lines
# Additional whitespace combined with auto-extenstion to nearest ticmark
set offset 20,20,20,20
replot
# Additional whitespace with no auto-extension to nearest ticmark
set xrange [*:*] noextend; set yrange [*:*] noextend
replot
unset multiplot

gnuplot: Joined axes with overlapping tics

A while back I found a method to join Axes in a nice way. Now that I revisit the plot-making for a report I find that I'm not satisfied...
The reason for this is the overlap between the labels at the tics of my plot. Since I joined the axes, the last of the left and first of the right plot tics will overlap, shown in the below example with random sin and cos plotted.
How can I circumvent this in a general way. Please note that I will be plotting a lot of figures like these in series, figuring out each of these tics depending on the values of my data is not an option for me.
Thanks in advance!
My plot-file: JointAxes.gp
# Generic gnuPlot script for plotting multiple plots in a single figure
# Resetting all variables. Standard for all plots.
reset
# Setting (terminal) options.
set terminal pdfcairo color font ",8"
set output 'JointAxes.pdf'
# Option to plot multiple graphs in one picture, note the number of figs here is 4 (2 by 2).
set multiplot layout 2,2 rowsfirst
# Macro's needed to produce a figure with all plots 'touching'.
set macros
# Small plot labels
LABEL = "at graph 0.9,0.9"
# Axes adjustment
set format x "%.1f"
XAXE = 'set xlabel "Extent"; set xtics -2*pi,pi/3 # N.B. tics should be changed due to conjoined axes.
YAXE = 'set ylabel "Amplitude"; set ytics -1,0.25
NOX = "unset xtics;\
unset xlabel"
NOY = "unset ytics;\
unset ylabel"
# Locking the graphs at fixed points in the figure
# Margins for each row resp. column
TMARGIN = "set tmargin at screen 0.90; set bmargin at screen 0.55"
BMARGIN = "set tmargin at screen 0.55; set bmargin at screen 0.20"
LMARGIN = "set lmargin at screen 0.10; set rmargin at screen 0.50"
RMARGIN = "set lmargin at screen 0.50; set rmargin at screen 0.90"
# General plot markup
unset key
# Legend/key adjustment
# set key samplen 3 # length of legend colour-bar
# set key spacing 1 # spacing between samples
# Optional: Adjusting range
set yrange [-1:1]
set xrange [-pi:pi]
# Plotting the first of the 'sub'-plot
#YAXE; #NOX
#TMARGIN; #LMARGIN
set label 1 'a' #LABEL
plot sin(x)
# Plotting the second 'sub'-plot, i.e. a new plot command.
#NOX; #NOY
#TMARGIN; #RMARGIN
set label 1 'b' #LABEL
plot cos(x)
# Plotting 3rd
#YAXE; #XAXE
#BMARGIN; #LMARGIN
set label 1 'c' #LABEL
plot sin(x + 1.57)
#And Fourth
#NOY; #XAXE
#BMARGIN; #RMARGIN
set label 1 'd' #LABEL
plot cos(x + 1.57)
unset multiplot
set terminal wxt
set output
# OEF

Gnuplot: how to only draw xtics without tic lables on top

I want to draw xtics on top but without its tic labels:
This is what I want:
This is the code I tried:
set xtics mirror;
set border 2+4;
plot x;
This gave me:
How can I modify the script to get what I want?
You can remove the tick labels with set format x '', but that still leaves the xtics at the bottom.
In my opinion, the best way is to use only the x2-axis
set ytics nomirror
unset xtics
set x2tics nomirror
set format x2 ''
set border 2+4
plot x axes x2y1
you can make the color of the font as the background color e.g. for white background
set xtics out offset -1.,0 scale 2.2 enhanced font 'Helvetica:bold,45' tc rgb "#FFFFFF"

gnuplot: making axes numbers smaller in epslatex makes my axes label disappear offscreen

I'm writing a script to generate three plots in a column (using multiplot and setting margins). They all share an x-axis, so it's only necessary to label that on the bottom plot, but they have separate y-axes.
I'm using the epslatex terminal in gnuplot to generate the plots with latex labels and axes. Basically, I need the numbers on the axis to use a smaller font size than the actual axis labels. So far, I've been doing this using,
reset
set term epslatex standalone color solid 10
set output 'myplot.tex'
set multiplot;
#Common width for all three plots is set
set lmargin at screen 0.15;
set rmargin at screen 0.90;
set format x ""; #Removes xlabels from plots without removing tic marks
#First plot
set tmargin at screen 0.98;
set bmargin at screen 0.72;
set ylabel '$Label Name 1$';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:3 w l lt 1 lw 3
#Second plot
set tmargin at screen 0.70;
set bmargin at screen 0.44;
set ylabel '$Label Name 2$';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:11 w l lt 2 lw 3
#Third plot
set tmargin at screen 0.42;
set bmargin at screen 0.16;
set xlabel 'Common Label Name';
set format x '\scriptsize{%g}'; # Here I reset the x axis so it shows on
this plot
set ylabel 'Label Name 3';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:5 w l lt 3 lw 3
unset multiplot;
So as you can see I use latex to format the numbers in a different size, specifically \scriptsize. For the xlabel at the end, everything works fine; the numbers are at a smaller font, and the xlabel prints just beneath it at the regular size. For the ylabels, however, the numbers DO appear smaller, but the actual label names don't appear on the plot.
At first I though they weren't being acknowledged somehow, but when I experimented with the margins, I found that if I move lmargin to the middle of the page, the ylabels reappear! It seems, for whatever reason, they're just being drawn some large distance from the axes themselves.
I've tried setting the labels with an offset, but that yields no joy.
The reason for this behaviour is, that gnuplot doesn't know, how the tics with LaTeX syntax will ultimately look like. The program tries to estimate the tic label length and adjusts the label positions accordingly.
If you have a format '\scriptsize %g', the tic labels seem to be very large:
set terminal epslatex standalone
set output 'label-offset.tex'
set format y '\scriptsize %g'
set ylabel 'ylabel'
plot x
set output
system('latex label-offset.tex && dvips label-offset.dvi && ps2pdf label-offset.ps')
Gnuplot version 4.2.6 doesn't consider the \scriptsize at all and you need a very large offset to compensate it: set ylabel 'ylabel' offset 14.
Since versoin 4.4 the behaviour is better, you need an much lower offset: set ylabel 'ylabel' offset 4.
Some remarks:
\scriptsize is a switch and doesn't take an argument. Consider set xlabel '\scriptsize{scriptsize} normal?'. To limit its effect, surround the text with brackets, like {\scriptsize %g}. But that is not necessary for tic labels, since they are in any case put in brackets.
To have italic text, use \textit{label name 1}, and not the math mode with $-signs.

Resources