Here is a snippet that might get you started:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import mpl_toolkits.mplot3d as plt3

data = np.random.random((8,8))**4
cmap = cm.RdBu

fig = plt.figure()
ax = plt3.Axes3D(fig)

d = 0.1

w, h = data.shape
for x in range(w):
    for y in range(h):
        ax.bar3d([x+d], [y+d], [0], 1-d, 1-d, data[x,y], cmap(data[x,y]))
ax.set_zlim3d((0, 1))
plt.show()


Obviously, you should replace data with the actual data you want to
plot (maybe numpy can help with the histogramming), and use an
appropriate cmap for your data.  Note that in this case the entire box
is a single color, not shaded up the side as in the example you
referenced; I actually like it this way but I also don't know how one
would do the shading in matplotlib.  I'll admit it's rather silly to
have to create all these boxes individually, but that's the only way I
could see to color each box according to its height.  The variable d
just puts gaps between boxes; you could set this to zero to make the
boxes adjacent.

I haven't figured out how to properly set the tick labels on the x and
y axis in a 3d plot like this.  Also, there are often some z-order
errors with boxes occluding each other when they shouldn't.  I don't
know the details of how these things work internally; maybe some
experts could weigh in here.

Cheers,
Matthew



On Thu, Oct 1, 2009 at 3:29 PM, Ernest Adrogué <eadro...@gmx.net> wrote:
> Hello all,
>
> What is the best way to plot a 2d histogram?
> (Note that a 2d histogram is a histogram of a bivariate variable,
> so it's got to be a 3d plot.)
>
> Ideally, it should look somewhat like this:
> http://www.desy.de/~mraue/public/rootTutorial/v0.2/histogram02.gif
>
> For now, I have tried to do surface plots, one for each "bin",
> but this way you only get the tops of a series of imaginary columns
> and it looks a bit namby-pamby if you know what I mean.
>
> Any idea will be appreciated.
>
> --
> Ernest
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to