Abelisto
Abelisto

Reputation: 15614

gnuplot: Heatmap like the visible spectrum for 3d surface

I have data (like series of (x,y,z) points) and I need to plot 3d surface using real spectrum colors (from (infra)red to (ultra)violet including green) according to z. So I need the heatmap something like
enter image description here

So, how I can to do this?

All fine except colorizing.

If it is necessary, there is my gnuplot script:

set hidden3d
set dgrid3d 47*4,205*1 gauss 2
set pm3d
set cbrange[1.007694:1.210099]
set xrange [] reverse
unset ztics
unset key
set view 10,70
set xlabel "x"
set ylabel "y"
set ticslevel 0

set term postscript eps enhanced monochrome
set output "plot-m.eps"
splot 'plot.d' with lines

set term postscript eps enhanced color
set output "plot-c.eps"
replot

set terminal png size 1024,768 enhanced font "DejaVu Serif,20"
set output "plot-c.png"
replot

And my sample picture is:enter image description here

Upvotes: 2

Views: 736

Answers (1)

Michael
Michael

Reputation: 5335

I became interested in your question, so I found this and made a gnuplot script. Here the palette is set to "functions", i.e. R, G and B are calculated in the range [0:1]. You can map your plotting range to a range [400:700] to get full spectrum for your plot. The range is 400 to 700 nm.

reset
set term pngcairo size 1200,800
set output 'colormap2.png'

R(k)=( \
l=k*300+400, \
(l>=400.0 && l<410.0)? (t=(l-400.0)/(410.0-400.0), (0.33*t)-(0.20*t*t)) : \
(l>=410.0 && l<475.0)? (t=(l-410.0)/(475.0-410.0), 0.14-(0.13*t*t)) : \
(l>=545.0 && l<595.0)? (t=(l-545.0)/(595.0-545.0), (1.98*t)-(t*t)) : \
(l>=595.0 && l<650.0)? (t=(l-595.0)/(650.0-595.0), 0.98+(0.06*t)-(0.40*t*t)) : \
(l>=650.0 && l<700.0)? (t=(l-650.0)/(700.0-650.0), 0.65-(0.84*t)+(0.20*t*t)) : \
0.0)


G(k)=( \
l=k*300+400, \
(l>=415.0 && l<475.0)? (t=(l-415.0)/(475.0-415.0), (0.80*t*t)) : \
(l>=475.0 && l<590.0)? (t=(l-475.0)/(590.0-475.0), 0.8+(0.76*t)-(0.80*t*t)) : \
(l>=585.0 && l<639.0)? (t=(l-585.0)/(639.0-585.0), 0.84-(0.84*t)) : \
0.0)

B(k)=( \
l=k*300+400, \
(l>=400.0 && l<475.0)? (t=(l-400.0)/(475.0-400.0), (2.20*t)-(1.50*t*t)) : \
(l>=475.0 && l<560.0)? (t=(l-475.0)/(560.0-475.0), 0.7-t+(0.30*t*t)) : \
0.0)

set palette model RGB functions R(gray),G(gray),B(gray)
set pm3d map
set samples 2000
set xrange [400:700]
set cbrange [400:700]
splot x

enter image description here

Upvotes: 2

Related Questions