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

Gnuplot:向colorbox添加无穷大值

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

    我想用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 inf inf 4.5 3.0 0.5 0.0 1.5
    0.5 0.0 0.5 inf inf 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
    

    这是对应的绘图 : enter image description here

    如您所见,矩阵包含无穷多个值。我想在颜色框中添加一个额外的颜色(例如蓝色),特别是对于无穷大的值(中间的大红色方块应该显示为蓝色)。

    起初,我认为我只需要在为colorbox定义的颜色值的末尾再添加一种颜色。但这将导致最后两种颜色(红色和蓝色)之间的颜色过渡,因为蓝色将是cbrange最大值的关联颜色。但非无穷大值的最大值应保持为6和红色。

    结果应该是这样的 : enter image description here

    有什么想法吗?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Gavin Portwood    7 年前

    您将需要类似以下三行的内容,根据所需的渐变手动填充颜色0-11(我使用了 this site 以在过去生成渐变。)

    set cbrange [0:6.5]
    set palette maxcolors 13 model RGB defined \
    ( 0 '#222222', 1 '#333333',   2 '#444444', \
      3 '#555555', 4 '#666666',   5 '#777777', \
      6 '#888888', 7 '#999999',   8 '#aaaaaa', \
      9 '#bbbbbb', 10 '#cccccc', 11 '#dddddd', 12 '#dd0000')
    set cbtics ("0" 0, "1" 1, "2" 2, "3" 3, "4" 4, "5" 5, "6" 6, "inf" 6.5)