友意白雑記帳

だいたい自分用の覚え書き

How to change colours in 3D plots? gnuplotで3D図の色を変える

今でも3Dの図を描くときにはgnuplotを使っている。今回、描画時の色スケールを変えたくなったので、そのやり方をメモしておく。以下がサンプルファイル。

#<><><><><><><><><>top of "plot3d_test.gnu"

set size ratio 1.0 #Use the same size for x&y.
f=100
a=0.49
b=0.81
f(x,y) = f*exp (-a*x*x -b*y*y) #Determine the function to plot.
#set pm3d map
set pm3d
set format cb "%2.1t{/Symbol \264}10^{%L}"
set isosamples 40 #Use the same pixels for x&y.
splot[0:2][0:2][] f(x,y)
pause -1 #Wait until ENTER

dc = f*0.1
set cbrange[0:dc*10]
set palette defined (0 "white", \
dc*1 "blue", \
dc*2 "turquoise", \
dc*3 "green", \
dc*4 "yellow", \
dc*5 "orange", \
dc*6 "salmon", \
dc*7 "red", \
dc*8 "violet", \
dc*9 "magenta", \
dc*10 "purple")

replot
pause -1 #Wait until ENTER

#<><><><><><><><><>end

 

これを走らせると以下のような図が描ける。

デフォルト設定だとこんな感じ。

色替えしたのがこちら。