Interpolating in a heatmap using Gnuplot.jl

@affans, you may want to use Interpolations.jl for smoothing and palette() for the color scheme. Example edited to include a contour:

using Gnuplot, Interpolations
n, m = 26, 31
x, y = 1:n, 1:m
fxy = [sin(u * v) for u = x, v = y]
@gsp x y fxy "w image notit" "set view map" "set auto fix" "set size ratio -1"
@gsp :- xlab = "x" ylab = "y" "set cblabel 'z'"
@gsp :- palette(:default) #choose gnuplot palette (:thermal, etc)
save(term="pngcairo size 640,480", output="matrix.png")

cubint = CubicSplineInterpolation((x,y),fxy)
xi, yi = 1.0:0.2:n, 1.0:0.2:m
fxyi = [cubint(u,v) for u = xi, v = yi]
@gsp xi yi fxyi "w pm3d notitle ls 1"  "set view map" "set auto fix" "set size ratio -1"
@gsp :- xlab = "x" ylab = "y" "set cblabel 'z'"
@gsp :- palette(:default) #choose gnuplot palette (:thermal, etc)
@gsp :- "set style line 1 lw 1"  # contour width = 1
@gsp :- "set linetype 2 lc rgb 'yellow'"  # contour will be linetype 2
@gsp :- "set contour" "set cntrparam levels discrete -0.7"  # contour at -0.7
save(term="pngcairo size 640,480", output="matrix_interpolated_with_contour.png")

For a full list of color schemes:

for x in palette_names()
	println(x)
end

Cubic interpolation result:
matrix_interpolated

Original matrix:
matrix

Cubic interpolation plus one contour at -0.7 level:
matrix_interpolated_with_contour

2 Likes