Contouring a 2D histogram

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Jun 27 11:59:39 EDT 2014


On 27/06/2014 13:09, Jamie Mitchell wrote:
> Hi all,
>
> I have plotted a 2D histogram like so:
>
> python2.7
> import netCDF4
> import iris
> import iris.palette
> import numpy as np
> import matplotlib as mpl
> import matplotlib.cm as cm
> import matplotlib.mlab as mlab
> import matplotlib.pyplot as plt
> from matplotlib.colors import from_levels_and_colors
>
> fig=plt.figure()
> nbins=20
> nice_cmap=plt.get_cmap('brewer_RdYlBu_11')
> colors=nice_cmap([5,6,7,8,9,10])
> levels=[1,2,3,4,5]
> cmap, norm=from_levels_and_colors(levels, colors, extend='both')
>
> H, xedges, yedges=np.histogram2d(te_Q0_con_sw,hs_Q0_con_sw,bins=nbins)
> Hmasked=np.ma.masked_where(H==0,H)
> plt.pcolormesh(xedges,yedges,Hmasked,cmap=cmap,norm=norm,label='Q0 control')
>
> # From this I get a 'scattered' 2D histogram.
>
> Does anyone know how I can contour that scatter?
>
> Thanks,
>
> Jamie
>

You're more likely to get answers from 
https://lists.sourceforge.net/lists/listinfo/matplotlib-users or, if you 
prefer the one stop shop, gmane.comp.python.matplotlib.general

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list