Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D view of 2D histogram (heat map) in gnuplot

How can I (or can I) present this gnuplot histogram:

enter image description here


in this style of 3D histogram view - in gnuplot?:

enter image description here


Using the same data and data format as in the gnuplot example in answer would be best.

like image 246
spinkus Avatar asked Apr 09 '17 04:04

spinkus


2 Answers

The questions of the OP: How can I ...

There are a few workarounds that produce an output resembling the sample that you show. They do not have all the bells and whistles you may want for formatting, but they are approximations which look "ok".

  1. As per http://lowrank.net/gnuplot/plotpm3d-e.html#6.9 , pm3d should do the trick for what you need. See also pm3d down in this link.

  2. If shading is essential, you can try using some of this. But you should work out quite a bit.

  3. Another poor-man approximation to what you are asking for is given here.

I do not have gnuplot here to test these.

... (or can I)

It is widely documented that there is no facility for a 3D histogram plot, and anything to do a real such plot with the corresponding options (shading, spacing, back walls, perspective view, selection of point of view, etc.) requires complex user programming.

like image 180
sancho.s ReinstateMonicaCellio Avatar answered Oct 13 '22 22:10

sancho.s ReinstateMonicaCellio


Closest thing available in gnuplot that doesn't involve significant hackery and/or preprocessing seems to be impulses style. The help docs even suggest their use for 3d bar charts:

To use this style effectively in 3D plots, it is useful to choose thick lines (linewidth > 1). This approximates a 3D bar chart.

Here is a simple example using impulses, and matrix style data as in the linked heatmap example:

set title ''
unset key
set xyplane 0
set view 60,300,1.2
set xrange [-0.5:5]
set yrange [-0.5:5]
splot '-' matrix with impulses lw 20
0 0 0 0 0 0 
0 1 2 3 4 5 
0 2 4 6 8 10 
0 3 6 9 12 15 
0 4 8 12 16 20 
0 5 10 15 20 25
e

enter image description here

The issue is gnuplot renders the impulses as 2d pen strokes. It would be ideal if there was a way to some how apply a 3d surface effect to those lines, but I don't think there is a way, since they are just lines, not surfaces.

You can also use vectors style to achieve similar result to impulses above, but with support for "rgb variable" (AFAIK impulses doesn't support this). This allows you to change color based on z-value - but still no 3d surface. You'll have to use a different data format for vectors style (AFAIK), but it's a simpler transform from matrix style data than some other hack require:

set xyplane 0
set view 60,301,1.2
set xrange [0.5:5]
set yrange [0.5:5]
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
splot '-' using 1:2:(0):(0):(0):3:(rgb($3*(255/25),0,0)) with vectors nohead lw 40
5 5 25
5 4 20
5 3 15
5 2 10
5 1 5
4 5 20
4 4 16
4 3 12
4 2 8
4 1 4
3 5 15
3 4 12
3 3 9
3 2 6
3 1 3
2 5 10
2 4 8
2 3 6
2 2 4
2 1 2
1 5 5
1 4 4
1 3 3
1 2 2
1 1 1
e

enter image description here

like image 1
spinkus Avatar answered Oct 13 '22 22:10

spinkus