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

I would like to show the values โ€‹โ€‹of a function of two variables, for example x+y

, as an image of a "bitmap". 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 getting 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, by color according to x+y

= - 4 by cbrange

?


Edit: it worked out:

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 - let's say I want the gradient in this range to be exported as a "smooth" gradient (no axes, ticks, marks of any kind) on a large PNG, say 3000x2000 pixels; what would be the best way to achieve this?

+3


source to share


1 answer


Starting with your edit: you just deactivate everything. Value:

unset colorbox
unset xtics
unset ytics
set border 0

      

Then by id you create a list of commands:

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 only get a gradient enter image description here

EDIT: To improve the gradient step and create a smoother image, you need to use pm3d

interpolate

.

set pm3d interpolate 4,4

      

enter image description here

+2


source







All Articles