[SciPy-user] how to plot the result of histogram2d

John Hunter jdh2358@gmail....
Fri Sep 5 10:49:32 CDT 2008

On Fri, Sep 5, 2008 at 10:36 AM, Johann Cohen-Tanugi
<cohen@slac.stanford.edu> wrote:
> hi, I hope someone can quickly point me to some doc.
> I can do imshow(histogram2d(x,y)[0]) but then I miss the x and y binning
> correct labels.
> If I do imshow(histogram2d(x,y)) I get:
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (115, 0))

matplotlib questions are best addressed to the matplotlib-users mailing list at


histogram2d returns H, xedges and yedges.  The first argument should
be passed to imshow, and the second two can be used to get the extents

In [26]: x, y = np.random.randn(2, 100000)

In [27]: H, xedges, yedges = np.histogram2d(x, y, bins=50)

In [28]: extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

In [29]: imshow(H, extent=extent)
Out[29]: <matplotlib.image.AxesImage object at 0x9377bcc>


More information about the SciPy-user mailing list