gnuplot - GNUPlot 中颜色条中的不规则百分位数抽动

标签 gnuplot colorbar

我有一个文本文件,其中包含三列:纬度、经度和百分比。文本文件如下所示(链接 here ):

25.00  -28.00    0.3
25.00  -27.00    0.7
25.00  -26.00    1.6
25.00  -25.00    4.3
25.00  -24.00   10.0
25.00  -23.00   18.2
25.00  -22.00   33.9
25.00  -21.00   49.1
...

我想在世界地图上将此属性绘制为热图(GNUPlot 世界地图文件可以从网站作者 here 下载)

问题出在颜色条上,我想按不规则区域(百分位数)对值进行分组。由于很难解释,如果我用 GNUPlot 得到什么,我会附上一张图像和另一个具有所需结果的图:

GNUplot 尝试: enter image description here

生成绘图的代码是:

set palette maxcolors 10
set palette defined (0 "#000090",1 "#000fff", 2 "#0090ff",3 "#0fffee",4 "#90ff70",5 "#ffee00",6 "#ff7000",7 "#ee0000",8 "#7f0000", 9 "#7f0050")
set cbtics (99.9 , 99.6, 99.0, 97.5, 95.0, 90.0, 75.0, 50.0, 20.0, 10.0);
plot [-30:40][25:70] "HeatMap_Test.txt" u 2:1:3 pt 5 ps 2 lc palette notitle, "world_10m.txt" with lines ls 1 notitle

期望的结果: enter image description here

除了 GNUPlot 中的颜色(它们不是最终的颜色)之外,您还可以看到颜色条控制呈线性分布(使超过 99.0 的颜色全部粘在一起),并且不按颜色条控制定义的区域进行分组.

有没有办法在 GNUPlot 中绘制这个图?

编辑:问题的第二部分继续 here

最佳答案

您可以定义一个阶跃函数,根据需要映射 z 列。

reset

step(x) = (x < 15.0  ? 0 : \
          (x < 35.0  ? 1 : \
          (x < 62.5  ? 2 : \
          (x < 82.5  ? 3 : \
          (x < 92.5  ? 4 : \
          (x < 96.25 ? 5 : \
          (x < 98.25 ? 6 : \
          (x < 99.3  ? 7 : \
          (x < 99.75 ? 8 : 9 )))))))))

set palette maxcolors 10
set palette defined (0 "#333399", 1 "#3333f7", 2 "#3373ff", 3 "#33c6ff", \
                     4 "#5affd2", 5 "#9cff8f", 6 "#dfff4c", 7 "#ffc733", \
                     8 "#ff7a33", 9 "#e53333")

set cbrange [-0.5:9.5]
set cbtics nomirror
set cbtics ( "99.9" 9, "99.6" 8, "99.0" 7, "97.5" 6, "95.0" 5, \
             "90.0" 4, "75.0" 3, "50.0" 2, "20.0" 1, "10.0" 0 )

set terminal pngcairo
set output "output.png"
set xrange [-30:40]
set yrange [ 25:70]
plot "HeatMap_Test.txt" u 2:1:(step($3)) notitle pt 5 ps 2 lc palette, \
     "world_10m.txt" notitle with lines ls 1 lc -1
set output

我多次嵌套三元运算符,将不规则百分比范围 0 ... 100 映射到线性 cbrange -0.5 ... 9.5。

这是 Gnuplot 4.6 的结果:

irregular percentile tics

关于gnuplot - GNUPlot 中颜色条中的不规则百分位数抽动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40887385/

相关文章:

python - 绘制颜色条时强制方形子图

python - 修改二维数组的 matplotlib colorbar 图上的轴

python - 将自定义刻度标签均匀地分布在颜色条上

gnuplot - 我想拟合一个带有整数参数的函数

c++ - 隐藏 C++ Gnuplot 管道控制台输出

plot - gnuplot 边距在多图模式下如何工作?

linux - 为什么我的命令对 gnuplot 不起作用?

gnuplot:如何增加图表的宽度

python - 使用 rasterized=True 时,Matplotlib 图(pcolormesh 和 colorbar)相对于它们的轴移动

python - Mayavi 为所有场景修复了颜色条