Smooth gradient display of function of two (xy) variables in gnuplot?

337 views Asked by At

I'd like to show the values of a function of 2 variables, say x+y, as a "bitmap" image. So I tried this, based on http://gnuplot.sourceforge.net/demo/heatmaps.html:

# Color runs from white to green
set palette rgbformula -7,2,-7
set cbrange [-5:5]
set cblabel "Value"
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set view map
splot x+y with image

... but I get nothing:

$ gnuplot -persist test.gp
"test.gp", line 45: warning: Image grid must be at least 2 x 2.

test.png

So how can I get the "pixel" at, say, x=-2, y=-2 to be colored according to x+y=-4 on the cbrange?


Edit: got that:

set palette rgbformula -7,2,-7
set cbrange [-5:5]
set cblabel "Value"
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set pm3d
unset surface
set view map
splot x+y

Outputs:

test.png


But - say I want the gradient in this range, exported as "smooth" gradient (no axes, ticks, marks of any kind) on a big PNG, say 3000x2000 pixels; what would be the best way to achieve that?

1

There are 1 answers

4
ztik On BEST ANSWER

Starting from your edit: You just to deactivate every thing. Meaning:

unset colorbox
unset xtics
unset ytics
set border 0

Then id you create the command list:

set palette rgbformula -7,2,-7
set cbrange [-5:5]
unset cblabel 
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set pm3d
unset surface
set view map

unset colorbox
unset xtics
unset ytics
set border 0

splot x+y

You get only the gradient enter image description here

EDIT: In order to improve the gradient step and create a smoother image you need to use pm3d's interpolate.

set pm3d interpolate 4,4

enter image description here