Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Ernest Adrogué <eadrogue@gm...>  20091001 22:29:06

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 nambypamby if you know what I mean. Any idea will be appreciated.  Ernest 
From: Gökhan Sever <gokhansever@gm...>  20091002 00:52:36

On Thu, Oct 1, 2009 at 5:29 PM, Ernest Adrogué <eadrogue@...> 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 nambypamby if you know what I mean. > > Any idea will be appreciated. > >  > Ernest > > >  > Come build with us! The BlackBerry® 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 912, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > Although it is not an exact histogram, if you are you looking for a Pythonic alternative you might consider using Mayavi. It has ready barchart plotting functionality. Probably with some effort a 2D histogram as you linked might be created. http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#barchart  Gökhan 
From: Ernest Adrogué <eadrogue@gm...>  20091002 10:09:04

Hi, 1/10/09 @ 19:23 (0500), thus spake Gökhan Sever: > Although it is not an exact histogram, if you are you looking for a > Pythonic alternative you might consider using Mayavi. It has ready > barchart plotting functionality. Probably with some effort a 2D > histogram as you linked might be created. > > http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#barchart Yes, it looks like it! I actually had already had a look at mayavi but found it overly complicated for a simple histogram. If it has simple bar chart functionality may be an option though. Cheers.  Ernest 
From: Matthew Neeley <mneeley@gm...>  20091002 01:17:30

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], 1d, 1d, 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 zorder 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é <eadrogue@...> 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 nambypamby if you know what I mean. > > Any idea will be appreciated. > >  > Ernest > > >  > Come build with us! The BlackBerry® 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 912, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Ernest Adrogué <eadrogue@gm...>  20091002 10:22:12

Hi, 1/10/09 @ 18:17 (0700), thus spake Matthew Neeley: > 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], 1d, 1d, 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 zorder > 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. Great!! I like the shading this way, so no problem here. Too bad about the rendering glitches though. Although, maybe that can be sorted out by increasing the distance between boxes...? I will experiment a little with this method of yours as it does basically what I wanted. If everything fails I think I will finally use a 2d plot using a colour map to represent the height of bars, as in here: http://www.davidbdean.com/wpcontent/uploads/hist2d.png Thanks a lot! Bye.  Ernest 