Meera
Meera

Reputation: 318

Gnuplot - Map with discrete color scheme (maxcolors?)

I'd like to plot a map with discrete color scheme and a textual color description.

But even though I set the maxcolors to 4, I get 6 colors. My options:

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

The outcome with maxcolors to 4 & the outcome with maxcolors to 3:

outcome 4 outcome 3

What is wrong when I set maxcolors to 4?

Upvotes: 1

Views: 2835

Answers (1)

Christoph
Christoph

Reputation: 48390

The values used in set palette defined are used only as relative values to determine the gradient. They do not correspond to the absolute values in your data.

I think your problem is that you have four colors, but only three segments. That seems to make problems with maxcolors. Independent of the maxcolors settings, you can define your palette as follows:

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

gives you:

enter image description here

So, with a little tweaking of the cbrange and the rmargin and the following script

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

you get the result (with 4.6.3):

enter image description here

Upvotes: 1

Related Questions