Gnuplot, can you use two different palettes worshi

2019-09-01 08:50发布

问题:

I want to have two different gradients. Is this possible with two different palettes? And yes, how to declare them?

回答1:

I guess the problem is that you don't set a fixed cbrange. The numerical values given in the set paletted defined statement are relative values. According to your previous questions you scale the color to the range [-1:1]. In that case, your relative values in the palette definition and those in the plots coincide. However, if you have only positive or only negative values, then you have effectively a cbrange of [-1:0] or [0:1]. Just use a set cbrange [-1:1] and it should work.

The following minimal example shows your first what happens without setting a cbrange, and then in the second plot the result with a fixed cbrange:

The file test.txt contains the values

1 5
2 3
3 2

The gnuplot script is:

set boxwidth 0.8 relative
set palette defined (-1 "#D30000", 0 "#00F000", 0 "#FFF900", 1 "#FF0700")

set style data boxes
set style fill solid 1.0 noborder
unset key
unset colorbox

set multiplot layout 1,2

set title 'wrong colors'
plot for [i=51:1:-1] 'test.txt' using 1:($2*i/51.0):(i/51.0) lc palette

set title 'correct colors'
set cbrange[-1:1]
replot
unset multiplot

The result with 4.6.3: