how to zoom a subplot in multiplot mode in gnuplot? - gnuplot

zooming in gnu plot is done by multi plot.
But what if we have zoom a particular subplot in multi plot?
It is like a multi plot within another multi plot.
need help!

Within a multiplot environment you can create plots wherever you want, their positions and sizes are set with the commands set origin and set size.
It is up to you whether the single plots are positioned side by side or one into another like in this example.
set terminal pngcairo
set output "multiplot.png"
set samples 1000
set xzeroaxis
set multiplot
set origin 0,0
set size 1,1
set xrange [-15:15]
plot cos(x) * x**2, sin(x) * x**2
set nokey
set origin 0.3, 0.07
set size 0.5, 0.45
set xrange [-2:2]
set yrange [-4:2]
set xtics 1
set ytics 2
replot
set origin 0.45, 0.14
set size 0.3, 0.2
set xrange [-0.1:0.1]
set yrange [-0.002:0.004]
set ytics 0.002
set xtics 0.1
replot
unset multiplot
Note that the values for origin and size are given relative to the complete picture, not relative to the previous plot.

Related

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.

Gnuplot parametric surface plot hidden3d / pm3d border problem

The last couple of hours I've been trying to produce an acceptable-looking plot of a 3D-Object. Now i'm totally stuck at somehow making Gnuplot draw the borders in respect to my 3D-object in a right way. The code I use is this:
reset
set term pngcairo enhanced size 800,600
set output "plot.png"
set grid xtics ytics ls 3 lw 1 lc rgb 'gray'
set xzeroaxis
set yzeroaxis
set samples 30,30
set isosamples 30,30
set style line 100 lt 5 lw 0.5 lc black
set palette gray
set cbrange [-1:1]
unset colorbox
set pm3d depthorder hidden3d implicit
set pm3d lighting primary 0.50 specular 0.6
set parametric
set urange [0:2*pi]
set vrange [0:2*pi]
set xrange [-3.1:3.1]
set yrange [-3.1:3.1]
set zrange [-1.1:1.1]
set xyplane at -1
set view 121,115
set xtics offset first 0,0, -0.1
set ytics offset first 0,0, -0.1
set ytics -2,1,2
set xtics -2,1,2
unset border
set border 4095 front lt black linewidth 2.000 dashtype solid
splot (2+cos(u))*cos(v),(2+cos(u))*sin(v),1*sin(v) lc rgb '#666666'
set output
If you plot that code it results in an image like this:
3D-Object Plot
As you can see the layering of Borders/Axes and Graph is somehow messed up. I spent some time playing around with different terminal types, or set border back / front / behind, or basically all the other options, but i could not succeed in making Gnuplot draw this the right way, which means, the borders surround my Object.
The only compromise solution i could find, is, if i choose certain different view-points Gnuplot gets it all right. But for the one i want the drawing does not work..
I would be very happy about any suggestions or hints!

rotating the xy plane of a 3D graph in gnuplot

I plotted a 3D graph with gnu plot, with the following commands
set term png
#set term post enh color eps font "Times-Roman, 15"
set output "order.png"
#set title ""
set key outside right bottom vertical reverse enhanced samplen 2 spacing 1.0 width 2 height 1
#set key font "Times-Roman,15"
set xlabel "\eta"
set ylabel "r"
set zlabel "\rho_0"
set xyplane 0
#set view 120,50
set grid
set grid ztics
set xtics 0.5
set ytics 0.5
set ztics 0.05
set tics font "Times-Roman,15"
set tics scale 0.5
set xrange [0:1] noreverse nowriteback
set yrange [0:1] noreverse nowriteback
set zrange [0:0.12] noreverse nowriteback
splot "order0.txt" u 1:2:3
and the plot is :
but I want it to be like the original plot(which is taken from a peper):
I searched the internet, but I just found
set view
which doesn't produce the one that I want.
It sounds as if you would like to rotate the plot around the z-axis so that the r-axis is in "front". The second number in the "set view" command will do that. Try "set view 45 300". Sorry if you meant something else.

gnuplot: plotting single palette in multiplot mode

I would like to ask some help on the following topic:
The following code produces 3 plots (3 rows, 1 column) on the same page:
set terminal postscript color
set output "test.ps"
file="test.dat"
set palette rgb 33,13,10
set cblabel "[km]"
set cbtics 2.5, 5, 20 format "%.0f"
set lmargin at screen 0.08
set rmargin at screen 0.88
# BUILD FROM BOTTOM TO TOP #
TOP=0.92 #
DY = 0.27 # DIMENSION OF Y
set multiplot
set grid
set offset 0, 0, graph 0.05, graph 0.05
#unset colorbox
# BOTTOM GRAPH #
set xlabel "Second of the Week [s]"
set ylabel "Up [m]" offset 1.5
set ytics -0.7, 0.2, 0.4
set yrange[-0.75:0.35]
set tmargin at screen TOP-2*DY
set bmargin at screen TOP-3*DY
plot file u 1:12:3 notitle palette
# MIDDLE GRAPH #
set xtics format ''
unset xlabel
set ytics -0.3, 0.2, 0.8
set yrange[-0.35:0.75]
set ylabel "North [m]"
set tmargin at screen TOP-DY
set bmargin at screen TOP-2*DY
plot file u 1:11:3 notitle palette
# TOP GRAPH #
set title "test"
set ylabel "East [m]"
set ytics -0.7, 0.2, 0.4
set yrange[-0.9:0.25]
set tmargin at screen TOP
set bmargin at screen TOP-DY
plot file u 1:10:3 notitle palette
unset multiplot
The above code produces the following plot:
In the plots, the data are shown according to the distance from an origin. The distance is color coded and the palette used is plotted on the right of each graph.
My question would be:
- how do I obtain the same graph but with a single vertical palette on the right of the 3 plots? I want a single palette to be shown from the top of the first graph (East) to the bottom of the third graph (Up). This would allow me to enlarge the palette as well and would result in a cleaner plot.
Any help is greatly appreciated.
For the first one use
set colorbox user origin screen 0, screen 0.05 size screen XX, screen YY
Where you need to set XX and YY to fit the desired colorbox width and heigh of the three plots.
Then for the second two plots, just set
unset colorbox

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