2
votes

I want to plot a 3D histogram with Gnuplot using a style commonly used in Matlab. The sequence of steps I follow are:

set palette defined ( 0 '#000090',\
                      1 '#000fff',\
                      2 '#0090ff',\
                      3 '#0fffee',\
                      4 '#90ff70',\
                      5 '#ffee00',\
                      6 '#ff7000',\
                      7 '#ee0000',\
                      8 '#7f0000')

set pm3d at s
set view map 
splot 'test.dat' u 1:2:3

The data to make the plot is provided below. The resulting plot looks like this: enter image description here

As you may see in the data below, most of the entries are zero which makes the plot very blue. In Matlab one can make this type of histograms and zero values have a white color. Just the points which are not zero have a color as in the palette above. I would like to have those points in white because that would emphasize the actual sampled region.

I wonder if we can do that in Gnuplot. I tried omitting the zeroes in the data file but it resulted in a pointy-corners plot.

Additionally, I modified the palette defining the zero value explicitly as here:

set palette defined ( 0 '#ffffff',\
                      1 '#000090',\
                      2 '#000fff',\
                      3 '#0090ff',\
                      4 '#0fffee',\
                      5 '#90ff70',\
                      6 '#ffee00',\
                      7 '#ff7000',\
                      8 '#ee0000',\
                      9 '#7f0000')

However, the borders of the sampled area look color violet:

enter image description here

Thanks.

   1           1           1
   1           2           0
   1           3           0
   1           4           0
   1           5           0
   1           6           0
   1           7           0
   1           8           0

   2           1           0
   2           2           0
   2           3           1
   2           4           2
   2           5           3
   2           6           0
   2           7           0
   2           8           0

   3           1           0
   3           2           0
   3           3           2
   3           4          10
   3           5          15
   3           6           2
   3           7           0
   3           8           0

   4           1           0
   4           2           0
   4           3           0
   4           4           5
   4           5           2
   4           6           1
   4           7           0
   4           8           0

   5           1           0
   5           2           0
   5           3           0
   5           4           3
   5           5           2
   5           6           0
   5           7           0
   5           8           0

   6           1           0
   6           2           0
   6           3           0
   6           4           2
   6           5           0
   6           6           0
   6           7           1
   6           8           0

   7           1           0
   7           2           0
   7           3           0
   7           4           0
   7           5           0
   7           6           0
   7           7           0
   7           8           0

   8           1           0
   8           2           0
   8           3           0
   8           4           0
   8           5           0
   8           6           0
   8           7           0
   8           8           0
2
Did you try setting the corresponding palette entry to white? - Cris Luengo
I tried setting the value of zero to #ffffff (white color), but the resulting plot looks odd at the borders. They look darker than the neighboring points. - armando
I don't know what that means. Do note that you have an 8x8 array, but are creating only 7x7 squares. The data is at the intersections. This might be a reason why the resulting plot looks odd at the borders. - Cris Luengo
Please, see the information I just added to the initial question. - armando
It looks to me that the grid is drawn in one color, and the border in a different color. If you look carefully, you can observe the same in the original plot. - Cris Luengo

2 Answers

6
votes

Plotting with pm3d averages the data points. If you want to plot exactly the data points as matrix, you must plot with image. To have certain values in white, define them as undefined with 1/0:

set palette defined ( 0 '#000090',\
                      1 '#000fff',\
                      2 '#0090ff',\
                      3 '#0fffee',\
                      4 '#90ff70',\
                      5 '#ffee00',\
                      6 '#ff7000',\
                      7 '#ee0000',\
                      8 '#7f0000')

plot 'test.dat' u 1:2:($3 == 0 ? 1/0 : $3) with image notitle

enter image description here

2
votes

Update

I just saw the answer above using image (I'll upvote that one), and that is probably the best way to accomplish what you asked for. In any case, I made a few tests with the data file and wanted to share just for completeness:

set term png
set out "tmp.png"

set palette defined ( 0 '#ffffff',\
                      1 '#000090',\
                      2 '#000fff',\
                      3 '#0090ff',\
                      4 '#0fffee',\
                      5 '#90ff70',\
                      6 '#ffee00',\
                      7 '#ff7000',\
                      8 '#ee0000',\
                      9 '#7f0000')

set xrange[0:8]
set yrange[0:8]

set pm3d explicit at s
set view map 

set multiplot layout 2,2

splot 'test.dat' u 1:2:3 not w pm3d
splot 'test.dat' u 1:2:3 not w p pt 5 ps 5 pal
splot 'test.dat' u 1:2:($3==0 ? 1/0:$3) not w pm3d

Resulting in this:

output