pig
pig

Reputation: 33

Define palette color based on the range of z values from a data file

Suppose I have a data file with x y z column, which looks like:

  -3.063052922487259      -3.141592741012573       401.3000000000000    
  -3.063052922487259      -3.063052922487259       1.290000000000000    
  -3.063052922487259      -2.984513103961945       0.920000000000000       

  -2.984513103961945      -3.141592741012573       0.100000000000000    
  -2.984513103961945      -3.063052922487259       10.80000000000000    
  -2.984513103961945      -2.984513103961945       1001.290000000000       

  -2.905973285436630      -2.984513103961945       514.4000000000000    
  -2.905973285436630      -2.905973285436630       131.0300000000000    
  -2.905973285436630      -2.827433466911316       129.3300000000000

The range of the values within the z column will define the color of the data points. For example, on the z column, if the value is between 0.0 and 0.3, the color of data points will be set as blue; if between 0.3 and 1, the color of data points will be set as orange; if between 400 and 1000, the color of data points will be set as navy.

So I write some code like this:

set xrange [0:15]
set yrange [0:-15]
set zrange [0:1400]
set cbrange [0.001:1400]
set palette defined ( 0 "goldenrod", 0.3 "blue", 1 "orange", 2 "cyan", 4 "yellow", 10 "green", 20 "pink", 50 'gold', 100 'purple', 400 'navy', 1000 "red")
set palette maxcolors 11
unset key
unset surface
splot "DATA.dat" using 1:2:3 with image

Which does not work. Any help?

Further update: I really want to explain clearer why does not work, but Stack Overflow does not allow me to further explain, because they require me to have 10 reputation points in order to post an image result. So I can not post my result due to lacking of reputation. But I do modify my data set, so you can see the xy-data is equidistance now.

So I just describe the problem by words, instead of image, which is that the color box is wrong. According to my code, between 400 and 1000 should be navy (just one color). But the color box on the image shows that between 400 and 1000, there are 5 different navy colors, from shallow navy to deep navy. How can I only have one navy color between 400 and 1000 please?

Upvotes: 1

Views: 1221

Answers (1)

Christoph
Christoph

Reputation: 48440

The maxcolors option doesn't work properly in your case because it only discretizes the underlying color gradient. You can use the test palette command to see how your actual palette looks like:

set palette defined ( 0 "goldenrod", 0.3 "blue", 1 "orange", 2 "cyan", 4 "yellow", 10 "green", 20 "pink", 50 'gold', 100 'purple', 400 'navy', 1000 "red")
set palette maxcolors 11
test palette

Wrong palette definition

You must also keep in mind, that the numbers used in the palette definition aren't absolute values on the cb-axis, but the values (in your case from 0 to 1000) are mapped to the actual cbrange (0.001 to 1400).

In order to get regions with constant color value, you do the following:

set palette defined (0 "goldenrod", \
                     0 "blue", 0.3 "blue", \
                     0.3 "orange", 1 "orange", \
                     1 "cyan", 2 "cyan", \
                     2 "yellow", 4 "yellow", \
                     4 "green", 10 "green", \
                     10 "pink", 20 "pink", \
                     20 "gold", 50 "gold", \
                     50 "purple", 400 "purple", \
                     400 "navy", 1000 "navy", \
                     1000 "red", 1400 "red")
test palette

Correct palette definition

Upvotes: 2

Related Questions