2017-05-04 79 views
1

我将标签添加到图中。我用鼠标跟着这个tutorial for moving label to best position,很高兴发现标签可以在鼠标位置重写。 但是一旦完成,我还没有找到任何方法来获得标签的文本值,如果有人想在稍后移动标签(如果需要在缩放时说更准确地调整位置)而不复制/粘贴标签的文字。获得gnuplot标签值?

在脚本中,文本被输入并保留,但我只想移动其标识的标签,并获取文本或任何其他方式来移动标签。

gnuplot> set label 1 "square" at 0,0 
> show label 
label 1 "square" at (0.00000, 0.00000, 0.00000) 
> moveLabel(labelId, text) = sprintf('call "label_loop.gnu" "%s" "%d"', text, labelId) 
> eval moveLabel(1, "square") -> should be: eval moveLabel(1) 

gnuplot-5.0的'label_loop.gnu'是the comment part

感谢您的任何gnuplot提示! 此致敬礼

回答

2

既然你提到你想调用函数就像eval moveLabel(1),我假设标签已经在你的脚本中使用set label ...以前已经设置。如果是这样的话,你可以修改label_loop.gnu为:

#make sure that label_number is an integer and not a string so that 
#it is not "misinterpreted" in "set label" 
label_number = int(ARG1); 

pause mouse any "adjust label" 

#any other button will quit the loop 
if(MOUSE_BUTTON == 1) { 

    #using ARG1 instead of label_number or int(ARG1) would 
    #create a new label with the content of ARG1 as its text 
    set label label_number at MOUSE_X,MOUSE_Y 

    print "\n moved label ".ARG1." to position: ",MOUSE_X,MOUSE_Y 
    replot 
    call 'label_loop.gnu' ARG1 
} 

,然后将它从主脚本,例如为:

set term x11 
set mouse 

set label 1 "square" at 0,0 
moveLabel(labelId) = sprintf('call "label_loop.gnu" "%d"', labelId) 

plot x 

eval moveLabel(1) 

的“绝招”这里是,如果你调用set label命令没有任何文字,Gnuplot只是更新位置,并保持原来的文字...

+0

非常感谢!我不知道我只能使用“设置标签{}”而没有“