I am trying to plot two overlaping figures (one "big" and another smaller "zoomed-in"). The thing is I can't have a solid background on the entire "small" figure, meaning including labels, ticks labels, etc.
Does anyone have an idea ?
Here is a SWE of my problem (EDITED being closer to my problem):
reset
set multiplot
plot sin(x)/x ls -1
set size 0.4,0.4
set origin 0.6,0.5
set object 1 rectangle from graph 0,0 to graph 1,1 behind fc rgb "#04AA40"
plot sin(x)/x ls -1
unset multiplot
It looks like you could use almost exactly the same code as you posted, but change the multiplot commands and the coordinates so that the rectangle you make overlaps the labels of the figure as well:
reset
set multiplot title "Plot 1"
set object 1 rectangle from graph 0.45,0.45 to graph 1.1,1.1 front fc rgb "#04AA40"
plot sin(x)/x ls -1
unset object 1
set size 0.5,0.5
set origin 0.45,0.45
plot sin(x)/x ls -1
unset multiplot
If that doesn't work, can you explain why you can't have a background on the entire small figure, as you say?
I answer to my own question by this code which is the closest thing I am looking for, but still not happy with it. If anybody has an idea of how I can get the computed margins automatically, this answer could be the one...
reset
set multiplot title "Plot 1"
plot sin(x)/x ls -1
xorig_sub=.1
yorig_sub=.5
width_sub=.35
height_sub=.35
lmarg_sub=0.09
bmarg_sub=0.06
rmarg_sub=0.025
tmarg_sub=0.02
xmin=xorig_sub
xmax=xorig_sub+width_sub+rmarg_sub+lmarg_sub
ymin=yorig_sub
ymax=yorig_sub+height_sub+tmarg_sub+bmarg_sub
set object 1 rectangle front from screen xmin,ymin to screen xmax,ymax fc rgb "#04AA40" fs solid
clear
replot
unset object 1
set lmargin at screen xmin+lmarg_sub
set rmargin at screen xmax-rmarg_sub
set bmargin at screen ymin+bmarg_sub
set tmargin at screen ymax-tmarg_sub
set size width_sub,height_sub # set the size of the second plot in plot units
set origin xorig_sub,yorig_sub # set the origin for the second plot in plot units
plot sin(x)/x ls -1
unset multiplot
I recently had the same issue and saw the post. It might be a bit late in the game, but for the sake of completeness:
reset
set multiplot
plot sin(x)/x ls -1
set size 0.4,0.4
set origin 0.6,0.5
set object 1 rectangle from graph 0,0 to graph 1,1 fc rgb "#04AA40" fillstyle solid 0.0 noborder
set ticks front
plot sin(x)/x ls -1
unset multiplot
Works with gnuplot 5.0.
Related
I have a look at https://stats.stackexchange.com/tags/data-visualization/info and it seems to me that maybe I can find an answer here... or maybe it is off-topic here too.
Is this plot typical of gnuplot?
Source: https://arxiv.org/pdf/2003.10405.pdf
It's not the default look of gnuplot.
But gnuplot is quite customizable, and the looks depend on the capability of the output device (terminal) used and the libraries it was built with.
It is not uncommon to have your own ~/.gnuplot or a site-wide /usr/local/share/gnuplot/<version>/gnuplotrc.
From the built-in help:
When gnuplot is run, it first looks for a system-wide initialization file
gnuplotrc. The location of this file is determined when the program is built
and is reported by show loadpath. The program then looks in the user's HOME
directory for a file called .gnuplot on Unix-like systems or GNUPLOT.INI on
other systems. (OS/2 will look for it in the directory named in
the environment variable GNUPLOT; Windows will use APPDATA).
Unless you are student that has to follow your institution's style guide, I would encourage you to develop your own style(s) based on the examples you can find online and your needs.
The information and examples available on gnuplotting.org is very valuable for that purpose.
As #Roland Smith said, gnuplot is quite customizable.
To help you see how customizable it is, see below a complete example which reproduces wanted plot.
reset
set encoding utf8
# ***** TERMINAL SETTINGS *****
set terminal wxt size 800,450 font "Consolas"
# ***** GENERAL SETTINGS *****
# tics, key, and border
set tics nomirror scale 1.5
unset key
set border 7
# linestyles
set style line 1 lc "black"
set style line 2 lc "red"
# margins
set lmargin screen 0.100
set rmargin screen 0.900
set bmargin screen 0.135
# xlabel, xrange, and (m)xtics
set xlabel "Time [sec]"
set xrange [0:2.2]
set xtics 0.2 tc ls 1
set mxtics 4
# ***** CREATING SOME DATA TO PLOT *****
# Gaussian function plus some noise
f(x,a,b,c) = a*exp(-(x-b)**2/(2*c**2)) + a*0.02*rand(0)
# Storing on datablock
# First one
set table $FlowData
plot f(x, 80.0, 0.25, 0.15)
unset table
# Second one
set table $PressureData
plot f(x, 35.0, 0.75, 0.20)
unset table
# ***** THE PLOTS *****
# Turning-on the multiplot mode to place both plots
set multiplot
# ***** FIRST PLOT SETTINGS *****
set ylabel "Flow [l/min]"
set yrange [-10:120]
set mytics 4
# Fist plot itself
plot $FlowData axes x1y1 w l ls 1 lw 2
# ***** SECOND PLOT SETTINGS *****
# Remove previous customizations
unset tics
unset xlabel
unset ytics
unset ylabel
# New customizations
set border 8 ls 2
set y2label "Pressure [mbar]" tc ls 2
set y2range [-5:60]
set y2tics tc ls 2
set my2tics 4
# Labels
set label "Compliance : 15 [ml/mbar]" at 0.95,100.0 offset 0, 0
set label "Resistance : 5 [mbar/l/sec]" at 0.95,100.0 offset 0,-1
set label "PEEP : 5 [mbar]" at 0.95,100.0 offset 0,-2
set label "Inspiratory Pressure : 30 [mbar]" at 0.95,100.0 offset 0,-3
# Second plot itself
plot $PressureData axes x1y2 w l ls 2 lw 2
unset multiplot
The result:
By default font usually looks different and axis titles are centered.
I am trying to create a graphic using gnuplot 5.0 with two scales in the same x axis. I have managed to create one using the multiplot option with the following code:
reset
set terminal pngcairo
set output "test.png"
unset key
set ylabel "Temperature (C)"
set ytics nomirror
set yrange[0:7]
set multiplot layout 1,2
set xrange [0:5.99] #Avoid plotting the last xtics in the first graphic
set xlabel "Heating time (minutes)"
set rmargin at screen 0.7
plot x
set xrange [0:4]
set xlabel "Seconds after stop"
set rmargin
set lmargin at screen 0.7
set xtics 1
unset ylabel
unset ytics
set y2tics nomirror
set format y2 ''
f(x) = a * exp (-x*b)
a=6
b=1
plot f(x)
With this result:
I want to generate several images like this one and add them in a multiplot arrangement, but I am not sure if using nested multiplots will be easy. Is there an easier way to obtain each of the images without using multiplot, like splitting the xaxis in two components?
Thanks in advance.
Just in case this still might be of interest to the OP or somebody else... You don't explicitly write whether you want to plot functions or data from a datafile. In your examples you use functions.
You can do something without "nested" multiplots, which would certainly be possible as well, but probably getting a bit confusing.
So, maybe the following might be easier. You basically set the xtics "manually". In order to avoid typing the same code several times you can use macros (check help macros).
Code:
### multiplot graph with different x-axis scales
reset session
# define functions
Temperature(x) = x<t0 ? x*a/t0 : a*exp(-(x-t0)*b)
myColor(col) = column(col)<t0 ? 0xff0000 : 0x0000ff
myTic(x,t) = sprintf("%g", x<=t ? x : x-t)
# define macro
myPlot = "\
set xrange[0:t0+t1]; \
set arrow 1 from first t0, graph 0 to first t0, graph 1 nohead; \
set label 1 'heating' center at first t0/2., graph 0 offset 0,-2; \
set label 2 'cooling' center at first (t0+t1/2.), graph 0 offset 0,-2; \
set xtics (); \
do for [i=0:int(t0/dt1)] { set xtics add (myTic(i*dt1,t0) i*dt1) }; \
do for [i=0:int(t1/dt2)] { set xtics add (myTic(i*dt2,t1) i*dt2+t0) }; \
plot '+' u 1:(Temperature($1)):(myColor(1)) w l lc rgb var "
set samples 200
set key noautotitle
set bmargin 3
set ylabel "Temperature"
set grid x,y
set multiplot layout 2,2
t0=6; t1=4; dt1=1; dt2=1; a=6; b=1
#myPlot
t0=4; t1=10; dt1=1; dt2=2; a=4; b=0.5
#myPlot
t0=20; t1=30; dt1=5; dt2=10; a=2; b=0.1
#myPlot
t0=4; t1=4; dt1=1; dt2=1; a=10; b=1
#myPlot
unset multiplot
### end of code
Result:
I set-up a multiplot like this:
set terminal wxt size 1500,900
set format x "%d%m%y %H:%M:%S"
set xdata time
set timefmt x "%Y%m%dT%H%M%S"
set key font ",6"
set lmargin 10
set rmargin 10
set multiplot layout 2,1
plot "output.txt" u 1:2 w lines axes x1y1, \
"output.txt" u 1:3 w lines axes x1y2
plot "output.txt" u 1:40 w lines axes x1y1, \
"output.txt" u 1:39 w lines axes x1y2
set y2tics border
unset multiplot
Which works, and gives me 2 plots, one above the other.
But pressing the "replot" button (or using zoom) causes the second plot to fill the window - completely hiding the first plot.
Yes, that's how replot behaves. The documentation says: „Note that in multiplot mode, replot can only reproduce the most recent component plot, not the full set.“.
So, what you can do is to put the whole set multiplot ... unset multiplot stuff in an external file, load it, and then load it again. Or put that stuff in a string and eval it several times.
I had the same issue. Solved it with a loop:
set term wxt enh
do for [IDX = 0:1] {
if (IDX==1) {
set terminal png enhanced
set output 'temp.png'
}
set multiplot
set size 1,1
set origin 0,0
plot sin(x)
set size 0.5,0.35
set origin 0.13,0.63
plot cos(x)
unset multiplot
}
set output
set term wxt enh
Here is another workaround. It does not answer the question directly, but it could give idea to other similar issues. Put header, and a footer 'reread', then two context could be choosen for a similar multiplot (done twice)
if (exists("rehearse")) rehearse=1+rehearse; set term x11
if (!exists("rehearse")) rehearse=0; set term png; set output sprintf("test_palette_%s.png", system("date +\"%F\""))
pr "rehearse=".rehearse; show term #<= comment printing
set samples 100; set isosample 100,100
set xrange [0:1]; set yrange [0:1]
set palette defined (0 "white", 1 "red")
set autoscale cbfix; unset colorbox; unset key
set multiplot layout 2,2
plot '++' using 1:2:1 with image
plot '++' using 1:2:2 with image
plot '++' using 1:2:(-$1) with image
plot '++' using 1:2:(-$2) with image
unset multiplot
if(rehearse < 1) reread
I want to do something like that:
gnuplot_script.gp :
reset
set term x11 persist
set grid
set size 1,1
set multiplot
i = 0
while (i < 5) {
set size 0.5,0.5
set origin 0,0.5
plot i*sin(x)
set size 0.5,0.5
set origin 0.5,0.5
plot i*cos(x)
pause 0.5
i = i + 1
}
unset multiplot
I wish to see it animated, but everything just being smeared on the screen...
Is there any other way to do it ?
Thanks
I solved it...
If you put the "set unset" inside the "while" loop, it works
I'm trying to put two figures side by side using gnuplot with multiplot.
I want the resulting image to be rectangular so I use set size 2, 1. I also set the set multiplot layout 1, 2 option. However, the resulting image only uses the left part of the available space. Any help will be appreciated.
Thanks
Ahmet
Here is the resulting image
http://tinypic.com/r/33mlz04/6
And below is the gnuplot commands I'm using.
set terminal postscript eps color enhanced
set output 'figure.eps';
set size 2,1;
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
Although I'm not very sure, with some trial and error I have solved it
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1,0.5;
set multiplot layout 1, 2 ;
set title "Figure 1";
set size 0.5,0.5;
plot "data/data1.txt"
set title "Figure 1";
set size 0.5,0.5;
plot "data/data2.txt"
unset multiplot
Try something like:
set terminal postscript eps color enhanced size 10,5
set output 'figure.eps';
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
When you set the size on the terminal specification line, that determines the actual size of the plot canvas (in inches in this case). When you use set size on a separate line, that sets the size of the plot in relative units of the canvas size. This is different in older versions of gnuplot. For perhaps a better explanation, try help set size in gnuplot.
For even more control over the size/position of the plot, you can use set origin in conjuction with set size to change the placement and size of each plot. Finally, the most control can be achieved with set lmargin at <place> (and set rmargin ...) and so-on for tmargin and bmargin where the "lrtb" stand for left, right, top and bottom respectively.
So, to get a plot to fill all of the available space (left to right), you could:
set multiplot
set lmargin at 0
set rmargin at .5
plot sin(x)
set lmargin at .5
set rmargin at 1
plot cos(x)
unset multiplot
However, this is (usually) overkill. Usually gnuplot tries to make the margins big enough for your labels and such, but setting the margin explicitly disables that. I would suggest you go with the solution by andyras.
if you are having problems using this method for more than 2 figures add 'set origin 0,0' after 'set size 0.5,0.5'.
For example, for three figures :
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1.5,0.5;
set multiplot layout 1, 3 ;
set title "Figure 1";
set size 0.5,0.5;
set origin 0,0
plot "data/data1.txt"
set title "Figure 2";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
set title "Figure 3";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
unset multiplot