问题描述
我确实喜欢gnuplot 5中的新超文本功能;但我仍然缺少一些东西:我不仅希望将鼠标悬停在某个点附近以阅读一些隐藏的文本,而且还希望能够捕获超文本.
I do love the new hypertext feature in gnuplot 5; but I am still missing something: I would like not just to hover near a point to read some hidden text, but I also would like to be able to capture the hypertext.
如果此超文本是鼠标变量(就像MOUSE_X和MOUSE_Y一样),则捕获它将是一件容易的事;但是,事实并非如此.
If this hypertext were a mouse variable (just like MOUSE_X and MOUSE_Y), capturing it would be an easy task; however this seems not to be the case.
有人可以解决此问题吗?
Has anybody a workaround to accomplish this task?
推荐答案
在这方面,可能很有趣的是,在最新版本(-rc1
)中,一次单击鼠标左键即可将超文本复制到剪贴板中,请参见 https://stackoverflow.com/a/61924355/11769765 .
In this respect it might be interesting, that in the newest version (-rc1
) a single left-click shall copy the hypertext into clipboard, see https://stackoverflow.com/a/61924355/11769765.
对于gnuplot 5.2等较旧的版本,以下代码是一种(不太有效的)变通方法,获取最近的数据点:
For older versions like gnuplot 5.2, the following code is a (not very efficient) work-around tograb the closest data point:
set print $Data
do for [x=-5:5] {
print x, x**2
}
unset print
set table $Text
plot $Data us (sprintf("x=%g, y=%g",$1,$2)) w table
unset table
array snappoint[1]
set macro
myplot = 'plot $Data u 1:2:($Text[$0+1]) w labels hypertext point pt 7 lc 1 title "f(x)"'
bind Button1 'mx=MOUSE_X; my=MOUSE_Y; i=1;\
set table $distance; \
plot $Data u (d=sqrt(($1-mx)**2+($2-my)**2), di=$0==0?(xi=$1,yi=$2,d):\
(d<di?(i=int($0+1),xi=$1,yi=$2,d):di), d) w table;\
unset table;\
print i," ", $Text[i];\
@myplot, snappoint us (xi):(yi) pt 6 ps 2 lc 3 t $Text[i]'
@myplot
单击鼠标左键标记最接近的点并打印例如3 x=-3, y=9
到控制台.
A left click marks the closest point and prints e.g. 3 x=-3, y=9
to the console.
为简单起见,此处仅使用轴坐标来计算距离,而屏幕坐标会更好.可以使用变量GPVAL_X_MIN
等进行转换.
For simplicity, the distance is computed here only with axis coordinates, while screen coordinates would be better. The transformation could be done with variables GPVAL_X_MIN
, etc.
这篇关于在gnuplot 5中捕获超文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!