Search code examples
gnuplot

Gnuplot heatmap interpolation with svg


I am trying to plot a heatmap using gnuplot (5.2.8) with the SVG terminal. Gnuplot interpolates the colors between the center points of the cells.

When I use the pdf terminal the result is as expected and the cells are clear and uniform faces. How do I turn the interpolation for the SVG terminal off?

#set terminal svg size 600,600
set terminal pdf size 600,600
set style line 12 lc rgb '#ffffff' lt 1 lw 5
set border front 15 ls 12
set grid front ls 12

set datafile separator ','

percent_sample(sample) = sprintf("sample_%d/configuration.csv", sample)

set palette defined (0  '#c00000', 1 '#0000cc') model RGB
unset colorbox

#set cbrange[0:1]

set xrange [-0.5:9.5]
set yrange [-0.5:9.5]

unset key

set tics scale 0

unset xlabel
set xtics 0.5,1

unset ylabel
set ytics 0.5,1

set tmargin 0
set bmargin 0
set lmargin 0
set rmargin 0

#set view map


set output sprintf("sample_conf_%d.pdf", i)
plot percent_sample(i) matrix  with image


Solution

  • It is not gnuplot that does the interpolation - it is the SVG viewing program. Leaving aside the question of how you might persuade the viewer not to do this, you can prevent it from happening by using the keyword pixels in the gnuplot command:

    plot percent_sample(i) matrix with image pixels
    

    This tells the program to describe each pixel in the output image as a separate rectangle rather than merging them into a stream of contiguous pixels. See also:

    heatmaps demo