1
votes

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?

1
Please include the actual data for this plot. How do you want your colorbox to look like? You have four colors but only three segments... What about something like set palette defined (0 "white", 1 "white", 1 "grey", 2 "grey", 2 "black", 3 "black", 3 "blue", 4 "blue") without setting maxcolors? Maybe you also need to set set autoscale cbfix (depends on your actual data). - Christoph
In the best case it would look like this: i60.tinypic.com/sv5ssk.png - Link to the File with data: dropbox.com/s/zlfp1ds53rxn634/testGnu.txt - Meera
What you suggested actually works fine, thank you! - Meera

1 Answers

1
votes

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