2017-05-04 101 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

非常感謝!我不知道我只能使用「設置標籤{}」而沒有「