gnuplot: 防止在一个轴上缩放

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

gnuplot: prevent zoom on one axis

问题

是可能阻止一个轴上的缩放吗?
我认为,在旧版本中只需使用 set yrange [-1.1:1.1:] 来确实固定范围,而pl [][-1.1:1.1] 只是初始化范围。

但现在,使用鼠标缩放不再遵守范围。

英文:

It is possible to prevent zooming on one axis?<br>
I think, in older version just set yrange [-1.1:1.1:] really fixed the range, while
pl [][-1.1:1.1] only initialised the range.

But now, zooming with the mouse does not respect the range anymore.

答案1

得分: 1

I assume that you are using either wxt or qt terminal.
The following is a workaround which in principle does what you are asking for.

Apparently, gnuplot 4.6.0 was keeping a fixed yrange with plot [][-1.1:1.1] sin(x) when zooming with the mouse. However, this behaviour changed for gnuplot>4.6.0.

For newer versions you could use a while loop with pause mouse to mimic this behaviour.

In the example below

  • two left mouse button clicks (MOUSE_KEY=1) will define the zoom-in x-range and
  • a right mouse click (MOUSE_KEY=3) will reset the x-range to the original range.
  • pressing ESC will stop the loop.

Script: (works for gnuplot>=5.0.0)

reset session

ymin = -1.1
ymax =  1.1
set yrange[ymin:ymax]

plot sin(x)

x00 = GPVAL_X_MIN
x11 = GPVAL_X_MAX
x1 = y1 = NaN
continue = 1
while (continue) {
    pause mouse keypress,button3,button1
    x0=x1;   x1=MOUSE_X
    y0=y1;   y1=MOUSE_Y
    mk = MOUSE_KEY
    if (mk==27) { continue=0 }   # press ESC to end loop
    if (mk==3)  { 
        set xrange[x00:x11]      # scale to original range
        x1=y1=NaN
    }
    if (mk==1 &amp;&amp; x0==x0 &amp;&amp; y0==y0) {
        xr0 = x11&gt;x00 &amp;&amp; x1&gt;x0 ? x0 : x1
        xr1 = x11&gt;x00 &amp;&amp; x1&gt;x0 ? x1 : x0
        set xrange[xr0:xr1]
        set yrange[ymin:ymax]
        x1=y1=NaN
    }
    replot
}
### end of script

Screen capture: (from wxt terminal, yellow dot=left click, red dot=right click)

英文:

I assume that you are using either wxt or qt terminal.
The following is a workaround which in principle does what you are asking for.

Apparently, gnuplot 4.6.0 was keeping a fixed yrange with plot [][-1.1:1.1] sin(x) when zooming with the mouse. However, this behaviour changed for gnuplot>4.6.0.

For newer versions you could use a while loop with pause mouse to mimic this behaviour.

In the example below

  • two left mouse button clicks (MOUSE_KEY=1) will define the zoom-in x-range and
  • a right mouse click (MOUSE_KEY=3) will reset the x-range to the original range.
  • pressing ESC will stop the loop.

Script: (works for gnuplot>=5.0.0)

### keep fixed y-range when mouse zooming
reset session

ymin = -1.1
ymax =  1.1
set yrange[ymin:ymax]

plot sin(x)

x00 = GPVAL_X_MIN
x11 = GPVAL_X_MAX
x1 = y1 = NaN
continue = 1
while (continue) {
    pause mouse keypress,button3,button1
    x0=x1;   x1=MOUSE_X
    y0=y1;   y1=MOUSE_Y
    mk = MOUSE_KEY
    if (mk==27) { continue=0 }   # press ESC to end loop
    if (mk==3)  { 
        set xrange[x00:x11]      # scale to original range
        x1=y1=NaN
    }
    if (mk==1 &amp;&amp; x0==x0 &amp;&amp; y0==y0) {
        xr0 = x11&gt;x00 &amp;&amp; x1&gt;x0 ? x0 : x1
        xr1 = x11&gt;x00 &amp;&amp; x1&gt;x0 ? x1 : x0
        set xrange[xr0:xr1]
        set yrange[ymin:ymax]
        x1=y1=NaN
    }
    replot
}
### end of script

Screen capture: (from wxt terminal, yellow dot=left click, red dot=right click)

gnuplot: 防止在一个轴上缩放

huangapple
  • 本文由 发表于 2023年2月23日 21:09:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545284.html
匿名

发表评论

匿名网友

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

确定