英文:
gnuplot and multiplot: zooming works only for last plot
问题
我正在创建一个在gnuplot中的多图,并且我想要在其中一个图上进行缩放。我使用鼠标来进行缩放,但在我缩放后,多图消失了,我得到了最后一个图在我最初想要在另一个图上进行缩放的相同区域的放大。
以下图片展示了我正在处理的问题:
我的代码如下:
# 可视化命令
set terminal qt size 1300,1200
#---坐标轴
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]
#---网格
set grid ytics mytics xtics mxtics # 为每个刻度绘制线
set grid # 启用网格
#---美化图形
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
# 让我们来绘制图形!
# 薄层透射
set title "薄层透射"
set yrange [-0.1:1.2]
plot 'results/Sm149tThinFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149tThinFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# 厚层透射
set title "厚层透射"
set yrange [-0.1:1.2]
plot 'results/Sm149tThickFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149tThickFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# J4 捕获
set title "J4 捕获"
set autoscale y
plot 'results/Sm149cJ4Final.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149cJ4Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# J3 捕获
set title "J3 捕获"
set autoscale y
plot 'results/Sm149cJ3Final.asc' using ($1):($2):($2) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149cJ3Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# 总捕获
set title "总捕获"
set xlabel "入射中子能量 (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 "实验", 'results/Sm149cFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
unset multiplot
有没有关于如何在多个多图中缩放的想法?
编辑 1
我根据 https://stackoverflow.com/questions/62148384/interactive-multiplot-with-shared-x-axis 中提供的答案修改了我的代码:
# 可视化命令
set terminal qt size 1300,1200
#---坐标轴
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]
#---网格
set grid ytics mytics xtics mxtics # 为每个刻度绘制线
set grid # 启用网格
#---美化图形
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
# 让我们来绘制图形!
# 薄层透射
set title "薄层透射"
set yrange [-0.1:1.2]
plot 'results/Sm149tThinFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149tThinFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# 厚层透射
set title "厚层透射"
set yrange [-0.1:1.2]
plot 'results/Sm149tThickFinal.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149tThickFinal.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# J4 捕获
set title "J4 捕获"
set autoscale y
plot 'results/Sm149cJ4Final.asc' using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title "实验", 'results/Sm149cJ4Final.asc' using ($1):($4) with lines lw 3 lc rgb 'red' title "SAMMY"
# J3 捕获
set title "J3 捕获"
set autoscale y
plot 'results/Sm149cJ3Final.asc' using ($1):($2):($2) with yerrorbars pt
<details>
<summary>英文:</summary>
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
[![enter image description here][1]][1]
[![enter image description here][2]][2]
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 https://stackoverflow.com/questions/62148384/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:
1. Shift + L
2. The last plot appears on the multiplot wondow anf the x-axes is still log
3. Again Shift + L
4. The x-axis becomes linear
5. Left mouse click
6. The multiplot appears with all x axes, linear.
[1]: https://i.stack.imgur.com/Fsgxr.png
[2]: https://i.stack.imgur.com/ug14S.png
</details>
# 答案1
**得分**: 1
以下是翻译好的部分:
脚本如下,经过修改和补充,来源于[此答案][1],可以进一步优化和适应您的需求。还可以查看`help mouse variables`。
**脚本:**(在gnuplot 5.2.8和wxt终端上测试过)
```gnuplot
### 多图中的缩放
reset session
# 创建一些测试数据
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 # 无对数x轴
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 # 中键单击退出
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 }
}
}
### 脚本结束
结果:(来自Win10,wxt终端的屏幕截图)
我正在做的事情:
- 使用鼠标放大
- 按下
l
键设置set logscale x
,再次按下l
键取消unset logscale x
- 按下
a
键设置set autoscale x
- ...
英文:
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:
- zooming-in with mouse
- pressing
l
forset logscale x
, andl
again forunset logscale x
- pressing
a
forset autoscale x
- ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论