英文:
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 && x0==x0 && y0==y0) {
xr0 = x11>x00 && x1>x0 ? x0 : x1
xr1 = x11>x00 && x1>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 && x0==x0 && y0==y0) {
xr0 = x11>x00 && x1>x0 ? x0 : x1
xr1 = x11>x00 && x1>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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论