Gnuplot - 具有离散颜色方案的地图(maxcolors?)

时间:2014-03-18 20:13:05

标签: gnuplot

我想绘制具有离散配色方案和文本颜色描述的地图。

但即使我将maxcolors设置为4,我也会得到6种颜色。我的选择:

set title "Lit Map for Point X:5.0, Y:14.0 with Compactness: 61.45415361382562"
set terminal pngcairo size 1500,500
set output "img.png"
set autoscale fix
set size ratio -1
set cbrange [0:3]
set palette maxcolors 4
set palette defined (0 "white", 1 "grey", 2 "black", 3 "blue")
set cbtics ("Free" 0,"Shadow" 1,"Environment" 2,"Placed Obstacle" 3)
plot '-' matrix with image

maxcolors到4&的结果maxcolors到3的结果:

outcome 4 http://i60.tinypic.com/2jaeo1f.png outcome 3 http://i60.tinypic.com/25gcpqh.png

将maxcolors设置为4时有什么问题?

1 个答案:

答案 0 :(得分:1)

set palette defined中使用的值仅用作确定渐变的相对值。它们与数据中的绝对值不对应。

我认为你的问题是你有四种颜色,但只有三种颜色。这似乎会导致maxcolors出现问题。独立于maxcolors设置,您可以按如下方式定义调色板:

set palette defined (0 "white", 1 "white", 1 "grey", 2 "grey", 2 "black", 3 "black", 3 "blue", 4 "blue")
test palette

给你:

enter image description here

所以,稍微调整cbrangermargin以及以下脚本

set title "Lit Map for Point X:77.0, Y:2.0 with Compactness: 53.70905606592658"
set terminal pngcairo size 1500,500
set output "pic.png"
set autoscale fix
set size ratio -1
set rmargin 10
set cbrange [-0.5:3.5]
set palette defined (0 "white", 1 "white", 1 "grey", 2 "grey", 2 "black", 3 "black", 3 "blue", 4 "blue")
set cbtics ("Free" 0, "Shadow" 1, "Environment" 2, "Placed Obstacle" 3)
plot '-' matrix with image notitle

你得到了结果(用4.6.3):

enter image description here