【问题标题】:How to get gnuplot label value?如何获取 gnuplot 标签值?
【发布时间】:2019-05-25 13:56:16
【问题描述】:

我正在为绘图添加标签。我用鼠标跟踪了这个tutorial for moving label to best position,很高兴发现标签可以在鼠标位置重写。

但是一旦完成,我还没有找到任何方法来获取标签的文本值,如果有人想稍后移动标签(如果需要在缩放时更准确地调整位置)而不复制/粘贴标签的文本。

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

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

【问题讨论】:

    标签: label gnuplot


    【解决方案1】:

    由于您提到要像 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 只会更新位置并保持文本原样......

    【讨论】:

    • 非常感谢!我不知道我只能使用没有“
    猜你喜欢
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2020-12-30
    • 2013-10-29
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多