gnuplot和multiplot:缩放仅适用于最后一个图。

huangapple go评论83阅读模式
英文:

gnuplot and multiplot: zooming works only for last plot

问题

我正在创建一个在gnuplot中的多图,并且我想要在其中一个图上进行缩放。我使用鼠标来进行缩放,但在我缩放后,多图消失了,我得到了最后一个图在我最初想要在另一个图上进行缩放的相同区域的放大。

以下图片展示了我正在处理的问题:

gnuplot和multiplot:缩放仅适用于最后一个图。

gnuplot和multiplot:缩放仅适用于最后一个图。

我的代码如下:

# 可视化命令
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&#39;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&#39;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 &quot;%.2f&quot;
    
    low_energy  = real(system(&#39;awk -F = &#39;&#39;{if (NR == 9) print $2 }&#39;&#39; 149Sm.sh&#39;))
    high_energy = real(system(&#39;awk -F = &#39;&#39;{if (NR == 10) print $2 }&#39;&#39; 149Sm.sh&#39;))
    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 &quot;Helvetica Bold,14&quot;
    set key box lw 1
    set log x
    
    
    set multiplot layout 5,1 columns
    # Let&#39;s plot the sucker!
    
    #Thin transmission
    set title &quot;Thin transmission&quot;
    set yrange [-0.1:1.2]
    plot &#39;results/Sm149tThinFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149tThinFinal.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #Thick transmission
    set title &quot;Thick transmission&quot;
    set yrange [-0.1:1.2]
    plot &#39;results/Sm149tThickFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149tThickFinal.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #J4 capture
    set title &quot;J4 capture&quot;
    set autoscale y
    plot &#39;results/Sm149cJ4Final.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cJ4Final.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #J3 capture
    set title &quot;J3 capture&quot;
    set autoscale y
    plot &#39;results/Sm149cJ3Final.asc&#39; using ($1):($2):($2) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cJ3Final.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #Total capture
    set title &quot;Total capture&quot;
    set xlabel &quot;Incident neutron energy (eV)&quot; font &quot;Helvetica Bold,14&quot; offset 0,0,0
    set autoscale y
    plot &#39;results/Sm149cFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cFinal.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
       
    
    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 &quot;%.2f&quot;
    
    
    low_energy  = real(system(&#39;awk -F = &#39;&#39;{if (NR == 9) print $2 }&#39;&#39; 149Sm.sh&#39;))
    high_energy = real(system(&#39;awk -F = &#39;&#39;{if (NR == 10) print $2 }&#39;&#39; 149Sm.sh&#39;))
    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 &quot;Helvetica Bold,14&quot;
    set key box lw 1
    set log x
    
    cond=1; while(cond) {
       set yrange [*:*]
    
    set multiplot layout 5,1 columns
    # Let&#39;s plot the sucker!
    
    #Thin transmission
    set title &quot;Thin transmission&quot;
    set yrange [-0.1:1.2]
    plot &#39;results/Sm149tThinFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149tThinFinal.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #Thick transmission
    set title &quot;Thick transmission&quot;
    set yrange [-0.1:1.2]
    plot &#39;results/Sm149tThickFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149tThickFinal.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #J4 capture
    set title &quot;J4 capture&quot;
    set autoscale y
    plot &#39;results/Sm149cJ4Final.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cJ4Final.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #J3 capture
    set title &quot;J3 capture&quot;
    set autoscale y
    plot &#39;results/Sm149cJ3Final.asc&#39; using ($1):($2):($2) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cJ3Final.asc&#39; using ($1):($4) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
    #Total capture
    set title &quot;Total capture&quot;
    set xlabel &quot;Incident neutron energy (eV)&quot; font &quot;Helvetica Bold,14&quot; offset 0,0,0
    set autoscale y
    plot &#39;results/Sm149cFinal.asc&#39; using ($1):($2):($3) with yerrorbars pt 7 ps 0.5 black title &quot;Experimental&quot;, &#39;results/Sm149cFinal.asc&#39; using ($1):($5) with lines lw 3 lc rgb &#39;red&#39; title &quot;SAMMY&quot;
    
       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&#39;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.8wxt终端上测试过

```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
  • ...

gnuplot和multiplot:缩放仅适用于最后一个图。

英文:

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 &#39;+&#39; 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 &quot;red&quot;
plot $Data u 1:3 w l lw 2 lc &quot;web-green&quot;
plot $Data u 1:4 w l lw 2 lc &quot;web-blue&quot;
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 for set logscale x, and l again for unset logscale x
  • pressing a for set autoscale x
  • ...

gnuplot和multiplot:缩放仅适用于最后一个图。

huangapple
  • 本文由 发表于 2023年7月11日 07:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定