1
votes

I want to draw a contour plot with gnuplot, where I want to point out some special features with special colors.

I define the contour plot by

set pm3d map
set palette defined (-1 "red", -0.1 "red", 0 "white", 0.1 "blue", 1 "blue")

This results in a color gradient which has a small area with a gradient from red to white to blue and the remaining part is red for negative numbers and blue for positive numbers.

My problem is now, that I would like to set gnuplot automatically to a symmetric scaling of the z-axis. But by specifying splot [][][-200:200] 'data' u 1:2:3 and a dataset with values from e.g. -300 to 100 gnuplot does an automatic rescale to [-200:100] which results in a misalignment of my colorscale (the white area is now around -50).

Is there a way to force a zrange or get an automatically symmetric scaled axis?

2

2 Answers

3
votes

I'm not sure I understand the problem, but have you considered:

set cbrange [-200:200]

From the documentation:

The `set cbrange` command sets the range of values which are colored using the current `palette` by styles `with pm3d`, `with image` and `with palette`. Values outside of the color range use color of the nearest extreme.

2
votes

To force a z range, try

set zr [-200:200]

before your plot command. To automatically scale the axis you could probably cook something up using stats. The main trick is to keep in mind that the color bar is in relative units. Something like this (untested):

datafile = 'data.dat'

stats datafile u 3 nooutput

# assume you want some data positive and some negative
if (stats_max*stats_min > 0) {
 print 'WARNING: all data has same sign.  Color bars may be weird.'
}

z0 = -1*min(abs(0.1*stats_min),abs(0.1*stats_max))
z1 = 0.0
z2 = -1*z0

set palette defined (stats_min "red", z0 "red", z1 "white",
                     z2 "blue", stats_max "blue")