Reputation: 586
I'm creating a multiplot in gnuplot and I would like to zoom in a region on one of the plots. I use the mouse to do so but what happens after I zoom in, is that the multiplots disappear and I get the last plot zoomed in the same region i wanted to zoom initially at the other plot.
The following figures show what I'm dealing with
My code is the following
# visual commands
set terminal qt size 1300,1200
#---Axes
set format y "%.2f"
low_energy = real(system('awk -F = ''{if (NR == 9) print $2 }'' 149Sm.sh'))
high_energy = real(system('awk -F = ''{if (NR == 10) print $2 }'' 149Sm.sh'))
set xrange [low_energy:high_energy]
#---Grid
set grid ytics mytics xtics mxtics # draw lines for each ytics and mytics
set grid # enable the grid
#---Make the plot aesthetically better
set border lw 2
set key at graph 0.99, 0.99
set key font "Helvetica Bold,14"
set key box lw 1
set log x
set multiplot layout 5,1 columns
# Let's plot the sucker!
#Thin transmission
set title "Thin transmission"
set yrange [-0.1:1.2]
plot 'results/Sm149tThinFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149tThinFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#Thick transmission
set title "Thick transmission"
set yrange [-0.1:1.2]
plot 'results/Sm149tThickFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149tThickFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#J4 capture
set title "J4 capture"
set autoscale y
plot 'results/Sm149cJ4Final.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cJ4Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#J3 capture
set title "J3 capture"
set autoscale y
plot 'results/Sm149cJ3Final.asc' using ($1):($2):($2) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cJ3Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#Total capture
set title "Total capture"
set xlabel "Incident neutron energy (eV)" font "Helvetica Bold,14" offset 0,0,0
set autoscale y
plot 'results/Sm149cFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
unset multiplot
Any idea on how to zoom in on individual multiplots?
EDIT 1
I modified my code according to the answer provided in Interactive multiplot with shared x-axis
# visual commands
set terminal qt size 1300,1200
#---Axes
set format y "%.2f"
low_energy = real(system('awk -F = ''{if (NR == 9) print $2 }'' 149Sm.sh'))
high_energy = real(system('awk -F = ''{if (NR == 10) print $2 }'' 149Sm.sh'))
set xrange [low_energy:high_energy]
#---Grid
set grid ytics mytics xtics mxtics # draw lines for each ytics and mytics
set grid # enable the grid
#---Make the plot aesthetically better
set border lw 2
set key at graph 0.99, 0.99
set key font "Helvetica Bold,14"
set key box lw 1
set log x
cond=1; while(cond) {
set yrange [*:*]
set multiplot layout 5,1 columns
# Let's plot the sucker!
#Thin transmission
set title "Thin transmission"
set yrange [-0.1:1.2]
plot 'results/Sm149tThinFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149tThinFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#Thick transmission
set title "Thick transmission"
set yrange [-0.1:1.2]
plot 'results/Sm149tThickFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149tThickFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#J4 capture
set title "J4 capture"
set autoscale y
plot 'results/Sm149cJ4Final.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cJ4Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#J3 capture
set title "J3 capture"
set autoscale y
plot 'results/Sm149cJ3Final.asc' using ($1):($2):($2) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cJ3Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
#Total capture
set title "Total capture"
set xlabel "Incident neutron energy (eV)" font "Helvetica Bold,14" offset 0,0,0
set autoscale y
plot 'results/Sm149cFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "Experimental", 'results/Sm149cFinal.asc' using ($1):($5) with lines lw 3 lc rgb 'red' title "SAMMY"
unset multiplot
pause mouse button1,button2
cond = MOUSE_KEY != 2 # exit on middle click
}
I sort of works. The issue is that when I use the mouse to zoom in, the multiplot disappears, then the last plots appears zoomed-in so I have to close the window to see the multiplots zoomed in. Same when I used keyboard commands to unzoom or switch from log to lin axes.
The desired behavior is to zoom on one plot , zoom all graphs with identical x and keeping y-autoscale.
What's happening i.e. when trying to unset log x-axis is:
Upvotes: 0
Views: 285
Reputation: 25988
The script below is modified and complemented from this answer and can certainly be further optimized and adapted to your needs. Also check help mouse variables
.
Script: (tested with gnuplot 5.2.8 and wxt terminal)
### zoom for multiplot
reset session
# create some test data
set table $Data
plot '+' u 1:(sin($1)):(10000*cos(2*$1)):(sin($1)+cos(2*$1)) w table
unset table
set lmargin 10
stop = 0
Lx = 0 # no log x-axis
while (!stop) {
set autoscale y
set multiplot layout 3,1
plot $Data u 1:2 w l lw 2 lc "red"
plot $Data u 1:3 w l lw 2 lc "web-green"
plot $Data u 1:4 w l lw 2 lc "web-blue"
unset multiplot
pause mouse button1,button2,keypress
stop = MOUSE_KEY == 2 # exit on middle click
if (MOUSE_KEY==97) { set autoscale x }
if (MOUSE_KEY==108) {
Lx=!Lx
if (Lx==1) { set xrange[0:GPVAL_X_MAX]; set logscale x }
else { unset logscale x }
}
}
### end of script
Result: (screen capture from Win10, wxt terminal)
What I was doing:
l
for set logscale x
, and l
again for unset logscale x
a
for set autoscale x
Upvotes: 1