hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs)
Generate a hexagonal binning plot of x
versus y
. If C
is :None:None:`None`
(the default), this is a histogram of the number of occurrences of the observations at (x[i], y[i])
.
If C
is specified, specifies values at given coordinates (x[i], y[i])
. These values are accumulated for each hexagonal bin and then reduced according to :None:None:`reduce_C_function`
, having as default the NumPy's mean function ( numpy.mean
). (If C
is specified, it must also be a 1-D sequence of the same length as x
and y
, or a column label.)
The column label or position for x points.
The column label or position for y points.
The column label or position for the value of :None:None:`(x, y)`
point.
Function of one argument that reduces all the values in a bin to a single number (e.g. :None:None:`np.mean`
, :None:None:`np.max`
, :None:None:`np.sum`
, :None:None:`np.std`
).
The number of hexagons in the x-direction. The corresponding number of hexagons in the y-direction is chosen in a way 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.
Additional keyword arguments are documented in DataFrame.plot
.
The matplotlib Axes
on which the hexbin is plotted.
Generate a hexagonal binning plot.
DataFrame.plot
Make plots of a DataFrame.
matplotlib.pyplot.hexbin
Hexagonal binning plot using matplotlib, the matplotlib function that is used under the hood.
The following examples are generated with random data from a normal distribution.
.. plot:: ('context', 'close-figs')
>>> n = 10000 >>> df = pd.DataFrame({'x': np.random.randn(n), ... 'y': np.random.randn(n)}) >>> ax = df.plot.hexbin(x='x', y='y', gridsize=20)
The next example uses C
and :None:None:`np.sum`
as :None:None:`reduce_C_function`
. Note that :None:None:`'observations'`
values ranges from 1 to 5 but the result plot shows values up to more than 25. This is because of the :None:None:`reduce_C_function`
.
.. plot:: ('context', 'close-figs')
See :>>> n = 500 >>> df = pd.DataFrame({ ... 'coord_x': np.random.uniform(-3, 3, size=n), ... 'coord_y': np.random.uniform(30, 50, size=n), ... 'observations': np.random.randint(1,5, size=n) ... }) >>> ax = df.plot.hexbin(x='coord_x', ... y='coord_y', ... C='observations', ... reduce_C_function=np.sum, ... gridsize=10, ... cmap="viridis")
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them