def hexbin(self, x, y, C = None, gridsize = <NUM_LIT:100>, bins = None,<EOL>xscale = '<STR_LIT>', yscale = '<STR_LIT>',<EOL>cmap=None, norm=None, vmin=None, vmax=None,<EOL>alpha=<NUM_LIT:1.0>, linewidths=None, edgecolors='<STR_LIT:none>',<EOL>reduce_C_function = np.mean,<EOL>**kwargs):
if not self._hold: self.cla()<EOL>self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)<EOL>x, y, C = cbook.delete_masked_points(x, y, C)<EOL>if iterable(gridsize):<EOL><INDENT>nx, ny = gridsize<EOL><DEDENT>else:<EOL><INDENT>nx = gridsize<EOL>ny = int(nx/math.sqrt(<NUM_LIT:3>))<EOL><DEDENT>x = np.array(x, float)<EOL>y = np.array(y, float)<EOL>if xscale=='<STR_LIT>':<EOL><INDENT>x = np.log10(x)<EOL><DEDENT>if yscale=='<STR_LIT>':<EOL><INDENT>y = np.log10(y)<EOL><DEDENT>xmin = np.amin(x)<EOL>xmax = np.amax(x)<EOL>ymin = np.amin(y)<EOL>ymax = np.amax(y)<EOL>padding = <NUM_LIT> * (xmax - xmin)<EOL>xmin -= padding<EOL>xmax += padding<EOL>sx = (xmax-xmin) / nx<EOL>sy = (ymax-ymin) / ny<EOL>x = (x-xmin)/sx<EOL>y = (y-ymin)/sy<EOL>ix1 = np.round(x).astype(int)<EOL>iy1 = np.round(y).astype(int)<EOL>ix2 = np.floor(x).astype(int)<EOL>iy2 = np.floor(y).astype(int)<EOL>nx1 = nx + <NUM_LIT:1><EOL>ny1 = ny + <NUM_LIT:1><EOL>nx2 = nx<EOL>ny2 = ny<EOL>n = nx1*ny1+nx2*ny2<EOL>d1 = (x-ix1)**<NUM_LIT:2> + <NUM_LIT> * (y-iy1)**<NUM_LIT:2><EOL>d2 = (x-ix2-<NUM_LIT:0.5>)**<NUM_LIT:2> + <NUM_LIT> * (y-iy2-<NUM_LIT:0.5>)**<NUM_LIT:2><EOL>bdist = (d1<d2)<EOL>if C is None:<EOL><INDENT>accum = np.zeros(n)<EOL>lattice1 = accum[:nx1*ny1]<EOL>lattice2 = accum[nx1*ny1:]<EOL>lattice1.shape = (nx1,ny1)<EOL>lattice2.shape = (nx2,ny2)<EOL>for i in range(len(x)):<EOL><INDENT>if bdist[i]:<EOL><INDENT>lattice1[ix1[i], iy1[i]]+=<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>lattice2[ix2[i], iy2[i]]+=<NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>lattice1 = np.empty((nx1,ny1),dtype=object)<EOL>for i in range(nx1):<EOL><INDENT>for j in range(ny1):<EOL><INDENT>lattice1[i,j] = []<EOL><DEDENT><DEDENT>lattice2 = np.empty((nx2,ny2),dtype=object)<EOL>for i in range(nx2):<EOL><INDENT>for j in range(ny2):<EOL><INDENT>lattice2[i,j] = []<EOL><DEDENT><DEDENT>for i in range(len(x)):<EOL><INDENT>if bdist[i]:<EOL><INDENT>lattice1[ix1[i], iy1[i]].append( C[i] )<EOL><DEDENT>else:<EOL><INDENT>lattice2[ix2[i], iy2[i]].append( C[i] )<EOL><DEDENT><DEDENT>for i in range(nx1):<EOL><INDENT>for j in range(ny1):<EOL><INDENT>vals = lattice1[i,j]<EOL>if len(vals):<EOL><INDENT>lattice1[i,j] = reduce_C_function( vals )<EOL><DEDENT>else:<EOL><INDENT>lattice1[i,j] = np.nan<EOL><DEDENT><DEDENT><DEDENT>for i in range(nx2):<EOL><INDENT>for j in range(ny2):<EOL><INDENT>vals = lattice2[i,j]<EOL>if len(vals):<EOL><INDENT>lattice2[i,j] = reduce_C_function( vals )<EOL><DEDENT>else:<EOL><INDENT>lattice2[i,j] = np.nan<EOL><DEDENT><DEDENT><DEDENT>accum = np.hstack((<EOL>lattice1.astype(float).ravel(), lattice2.astype(float).ravel()))<EOL>good_idxs = ~np.isnan(accum)<EOL><DEDENT>px = xmin + sx * np.array([ <NUM_LIT:0.5>, <NUM_LIT:0.5>, <NUM_LIT:0.0>, -<NUM_LIT:0.5>, -<NUM_LIT:0.5>,  <NUM_LIT:0.0>])<EOL>py = ymin + sy * np.array([-<NUM_LIT:0.5>, <NUM_LIT:0.5>, <NUM_LIT:1.0>,  <NUM_LIT:0.5>, -<NUM_LIT:0.5>, -<NUM_LIT:1.0>]) / <NUM_LIT><EOL>polygons = np.zeros((<NUM_LIT:6>, n, <NUM_LIT:2>), float)<EOL>polygons[:,:nx1*ny1,<NUM_LIT:0>] = np.repeat(np.arange(nx1), ny1)<EOL>polygons[:,:nx1*ny1,<NUM_LIT:1>] = np.tile(np.arange(ny1), nx1)<EOL>polygons[:,nx1*ny1:,<NUM_LIT:0>] = np.repeat(np.arange(nx2) + <NUM_LIT:0.5>, ny2)<EOL>polygons[:,nx1*ny1:,<NUM_LIT:1>] = np.tile(np.arange(ny2), nx2) + <NUM_LIT:0.5><EOL>if C is not None:<EOL><INDENT>polygons = polygons[:,good_idxs,:]<EOL>accum = accum[good_idxs]<EOL><DEDENT>polygons = np.transpose(polygons, axes=[<NUM_LIT:1>,<NUM_LIT:0>,<NUM_LIT:2>])<EOL>polygons[:,:,<NUM_LIT:0>] *= sx<EOL>polygons[:,:,<NUM_LIT:1>] *= sy<EOL>polygons[:,:,<NUM_LIT:0>] += px<EOL>polygons[:,:,<NUM_LIT:1>] += py<EOL>if xscale=='<STR_LIT>':<EOL><INDENT>polygons[:,:,<NUM_LIT:0>] = <NUM_LIT:10>**(polygons[:,:,<NUM_LIT:0>])<EOL>xmin = <NUM_LIT:10>**xmin<EOL>xmax = <NUM_LIT:10>**xmax<EOL>self.set_xscale('<STR_LIT>')<EOL><DEDENT>if yscale=='<STR_LIT>':<EOL><INDENT>polygons[:,:,<NUM_LIT:1>] = <NUM_LIT:10>**(polygons[:,:,<NUM_LIT:1>])<EOL>ymin = <NUM_LIT:10>**ymin<EOL>ymax = <NUM_LIT:10>**ymax<EOL>self.set_yscale('<STR_LIT>')<EOL><DEDENT>if edgecolors=='<STR_LIT:none>':<EOL><INDENT>edgecolors = '<STR_LIT>'<EOL><DEDENT>collection = mcoll.PolyCollection(<EOL>polygons,<EOL>edgecolors = edgecolors,<EOL>linewidths = linewidths,<EOL>transOffset = self.transData,<EOL>)<EOL>if bins=='<STR_LIT>':<EOL><INDENT>accum = np.log10(accum+<NUM_LIT:1>)<EOL><DEDENT>elif bins!=None:<EOL><INDENT>if not iterable(bins):<EOL><INDENT>minimum, maximum = min(accum), max(accum)<EOL>bins-=<NUM_LIT:1> <EOL>bins = minimum + (maximum-minimum)*np.arange(bins)/bins<EOL><DEDENT>bins = np.sort(bins)<EOL>accum = bins.searchsorted(accum)<EOL><DEDENT>if norm is not None: assert(isinstance(norm, mcolors.Normalize))<EOL>if cmap is not None: assert(isinstance(cmap, mcolors.Colormap))<EOL>collection.set_array(accum)<EOL>collection.set_cmap(cmap)<EOL>collection.set_norm(norm)<EOL>collection.set_alpha(alpha)<EOL>collection.update(kwargs)<EOL>if vmin is not None or vmax is not None:<EOL><INDENT>collection.set_clim(vmin, vmax)<EOL><DEDENT>else:<EOL><INDENT>collection.autoscale_None()<EOL><DEDENT>corners = ((xmin, ymin), (xmax, ymax))<EOL>self.update_datalim( corners)<EOL>self.autoscale_view()<EOL>self.add_collection(collection)<EOL>return collection<EOL>
call signature::

  hexbin(x, y, C = None, gridsize = 100, bins = None,
         xscale = 'linear', yscale = 'linear',
         cmap=None, norm=None, vmin=None, vmax=None,
         alpha=1.0, linewidths=None, edgecolors='none'
         reduce_C_function = np.mean,
         **kwargs)

Make a hexagonal binning plot of *x* versus *y*, where *x*,
*y* are 1-D sequences of the same length, *N*. If *C* is None
(the default), this is a histogram of the number of occurences
of the observations at (x[i],y[i]).

If *C* is specified, it specifies values at the coordinate
(x[i],y[i]). These values are accumulated for each hexagonal
bin and then reduced according to *reduce_C_function*, which
defaults to numpy's mean function (np.mean). (If *C* is
specified, it must also be a 1-D sequence of the same length
as *x* and *y*.)

*x*, *y* and/or *C* may be masked arrays, in which case only
unmasked points will be plotted.

Optional keyword arguments:

  *gridsize*: [ 100 | integer ]
    The number of hexagons in the *x*-direction, default is
    100. The corresponding number of hexagons in the
    *y*-direction is chosen such that the hexagons are
    approximately regular. Alternatively, gridsize can be a
    tuple with two elements specifying the number of hexagons
    in the *x*-direction and the *y*-direction.

  *bins*: [ None | 'log' | integer | sequence ]
    If *None*, no binning is applied; the color of each hexagon
    directly corresponds to its count value.

    If 'log', use a logarithmic scale for the color
    map. Internally, :math:`log_{10}(i+1)` is used to
    determine the hexagon color.

    If an integer, divide the counts in the specified number
    of bins, and color the hexagons accordingly.

    If a sequence of values, the values of the lower bound of
    the bins to be used.

  *xscale*: [ 'linear' | 'log' ]
    Use a linear or log10 scale on the horizontal axis.

  *scale*: [ 'linear' | 'log' ]
    Use a linear or log10 scale on the vertical axis.

Other keyword arguments controlling color mapping and normalization
arguments:

  *cmap*: [ None | Colormap ]
    a :class:`matplotlib.cm.Colormap` instance. If *None*,
    defaults to rc ``image.cmap``.

  *norm*: [ None | Normalize ]
    :class:`matplotlib.colors.Normalize` instance is used to
    scale luminance data to 0,1.

  *vmin*/*vmax*: scalar
    *vmin* and *vmax* are used in conjunction with *norm* to normalize
    luminance data.  If either are *None*, the min and max of the color
    array *C* is used.  Note if you pass a norm instance, your settings
    for *vmin* and *vmax* will be ignored.

  *alpha*: scalar
    the alpha value for the patches

  *linewidths*: [ None | scalar ]
    If *None*, defaults to rc lines.linewidth. Note that this
    is a tuple, and if you set the linewidths argument you
    must set it as a sequence of floats, as required by
    :class:`~matplotlib.collections.RegularPolyCollection`.

Other keyword arguments controlling the Collection properties:

  *edgecolors*: [ None | mpl color | color sequence ]
    If 'none', draws the edges in the same color as the fill color.
    This is the default, as it avoids unsightly unpainted pixels
    between the hexagons.

    If *None*, draws the outlines in the default color.

    If a matplotlib color arg or sequence of rgba tuples, draws the
    outlines in the specified color.

Here are the standard descriptions of all the
:class:`~matplotlib.collections.Collection` kwargs:

%(Collection)s

The return value is a
:class:`~matplotlib.collections.PolyCollection` instance; use
:meth:`~matplotlib.collection.PolyCollection.get_array` on
this :class:`~matplotlib.collections.PolyCollection` to get
the counts in each hexagon.

**Example:**

.. plot:: mpl_examples/pylab_examples/hexbin_demo.py