Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 383

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _pylab_examples-hexbin_demo:

pylab_examples example code: hexbin_demo.py
===========================================



.. plot:: /builddir/build/BUILD/matplotlib-1.2.0/doc/mpl_examples/pylab_examples/hexbin_demo.py

::

    """
    hexbin is an axes method or pyplot function that is essentially
    a pcolor of a 2-D histogram with hexagonal cells.  It can be
    much more informative than a scatter plot; in the first subplot
    below, try substituting 'scatter' for 'hexbin'.
    """
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    np.random.seed(0)
    n = 100000
    x = np.random.standard_normal(n)
    y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
    xmin = x.min()
    xmax = x.max()
    ymin = y.min()
    ymax = y.max()
    
    plt.subplots_adjust(hspace=0.5)
    plt.subplot(121)
    plt.hexbin(x,y, cmap=plt.cm.YlOrRd_r)
    plt.axis([xmin, xmax, ymin, ymax])
    plt.title("Hexagon binning")
    cb = plt.colorbar()
    cb.set_label('counts')
    
    plt.subplot(122)
    plt.hexbin(x,y,bins='log', cmap=plt.cm.YlOrRd_r)
    plt.axis([xmin, xmax, ymin, ymax])
    plt.title("With a log color scale")
    cb = plt.colorbar()
    cb.set_label('log10(N)')
    
    plt.show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)