代码之家  ›  专栏  ›  技术社区  ›  rweisse

Gnuplot:显示包含z值的鼠标悬停工具提示

  •  3
  • rweisse  · 技术社区  · 8 年前

    我希望gnuplot终端动态显示工具提示窗口或标签之类的内容,该窗口或标签显示相应打印单元格的z值(单击后或由鼠标悬停事件触发)。我的终端类型是 wxt 而唯一能得到 wxt公司 在状态栏的左下角显示鼠标坐标。工具提示的另一种替代方法是将状态栏中显示的坐标替换为z值。换句话说:我需要一些功能来动态显示鼠标位置的z值。

    下面是一个快速示例(在鼠标悬停或单击鼠标右键时,我希望看到相应正方形的z值):

    enter image description here

    这是对应的gnuplot输入:

    unset key
    set cbrange [0:6]
    set xrange [0:10]
    set yrange [0:5]
    set size ratio -1
    set cbtics out nomirror
    set palette maxcolors 12 model RGB defined (0 '#1a9641', 1 '#a6d96a', 2 '#ffffbf', 3 '#fdae61', 4 '#d7191c')
    $map1 << EOD
    5.5 4.0 3.5 1.0 0.5 5.0 4.5 3.0 1.5 0.0
    2.0 2.5 0.0 5.5 5.5 4.5 3.0 0.5 0.0 1.5
    0.5 0.0 0.5 5.5 5.5 0.0 0.5 0.0 1.5 0.0
    0.0 0.5 0.0 2.5 3.0 0.5 0.0 0.5 2.0 3.5
    0.5 1.0 2.5 4.0 3.5 2.0 2.5 0.0 0.5 1.0
    EOD
    plot '$map1' using ($1+.5):($2+.5):($3) matrix with image
    
    2 回复  |  直到 8 年前
        1
  •  3
  •   Christoph    8 年前

    使用打印数据 plot ... with labels hypertext 获取具有在将鼠标悬停在相应点上时显示的标签的点。因为 hypertext 选项仅在打印点时有效,必须首先使用超文本标签打印点,然后打印图像:

    unset key
    set cbrange [0:6]
    set xrange [0:10]
    set yrange [0:5]
    set size ratio -1
    set cbtics out nomirror
    set palette maxcolors 12 model RGB defined (0 '#1a9641', 1 '#a6d96a', 2 '#ffffbf', 3 '#fdae61', 4 '#d7191c')
    $map1 << EOD
    5.5 4.0 3.5 1.0 0.5 5.0 4.5 3.0 1.5 0.0
    2.0 2.5 0.0 5.5 5.5 4.5 3.0 0.5 0.0 1.5
    0.5 0.0 0.5 5.5 5.5 0.0 0.5 0.0 1.5 0.0
    0.0 0.5 0.0 2.5 3.0 0.5 0.0 0.5 2.0 3.5
    0.5 1.0 2.5 4.0 3.5 2.0 2.5 0.0 0.5 1.0
    EOD
    plot '$map1' using ($1+0.5):($2+0.5):(sprintf("%.1f", $3)) matrix with labels hypertext point pointsize 6,\
         '$map1' using ($1+.5):($2+.5):($3) matrix with image
    

    玩转 pointsize 更改悬停区域的大小。

        2
  •  3
  •   user8153    8 年前

    您可以使用 hypertext labels 为此,将数据块中的数据转换为单个标签需要一些工作。如果添加以下代码段

    do for [row=1:5] {
       rowdata = $map1[row]
       col = 1
       do for [value in rowdata] {
          set label value at col-0.5,row-0.5 center back  hypertext point pt 4 ps 8
          col = col+1
       }
    }
    

    plot 你得到了你想要的:

    enter image description here

    它的工作原理是在图像背景中放置一个大致与单元格大小相同的正方形点,并使每个点成为显示其值的超文本的锚。代替 back 具有 front 查看并调整这些点的大小。