Skip to content

Commit db52245

Browse files
committed
DOC: improved hexbin plot docstring
1 parent 4131149 commit db52245

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

pandas/plotting/_core.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,25 +2874,61 @@ def scatter(self, x, y, s=None, c=None, **kwds):
28742874
def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,
28752875
**kwds):
28762876
"""
2877-
Hexbin plot
2877+
Make hexagonal binning plots.
2878+
2879+
Make an hexagonal binning plot of `x` versus `y`, where `x`,
2880+
`y` are 1-D sequences of the same length, `N`. If `C` is `None`
2881+
(the default), this is an histogram of the number of occurrences
2882+
of the observations at (x[i],y[i]).
2883+
2884+
If `C` is specified, specifies values at given coordinates
2885+
(x[i],y[i]). These values are accumulated for each hexagonal
2886+
bin and then reduced according to `reduce_C_function`,
2887+
having as default
2888+
the numpy's mean function (np.mean). (If *C* is
2889+
specified, it must also be a 1-D sequence of the same length
2890+
as `x` and `y`.)
28782891
28792892
Parameters
28802893
----------
2881-
x, y : label or position, optional
2882-
Coordinates for each point.
2894+
x : label or position, optional
2895+
Coordinates for x point.
2896+
y : label or position, optional
2897+
Coordinates for y point.
28832898
C : label or position, optional
28842899
The value at each `(x, y)` point.
2885-
reduce_C_function : callable, optional
2900+
reduce_C_function : callable, optional, default `mean`
28862901
Function of one argument that reduces all the values in a bin to
28872902
a single number (e.g. `mean`, `max`, `sum`, `std`).
2888-
gridsize : int, optional
2889-
Number of bins.
2890-
`**kwds` : optional
2903+
gridsize : int, optional, default 100
2904+
The number of hexagons in the x-direction.
2905+
The corresponding number of hexagons in the y-direction is
2906+
chosen in a way that the hexagons are approximately regular.
2907+
Alternatively,
2908+
gridsize can be a tuple with two elements specifying the number of
2909+
hexagons in the x-direction and the y-direction.
2910+
kwds : optional
28912911
Keyword arguments to pass on to :py:meth:`pandas.DataFrame.plot`.
28922912
28932913
Returns
28942914
-------
2895-
axes : matplotlib.AxesSubplot or np.array of them
2915+
axes : matplotlib.AxesSubplot or np.array of them.
2916+
2917+
See Also
2918+
--------
2919+
matplotlib.pyplot.hexbin : hexagonal binning plot using matplotlib.
2920+
2921+
Examples
2922+
--------
2923+
2924+
.. plot::
2925+
:context: close-figs
2926+
2927+
>>> from sklearn.datasets import load_iris
2928+
>>> iris = load_iris()
2929+
>>> df = pd.DataFrame(iris.data, columns=iris.feature_names)
2930+
>>> hexbin = df.plot.hexbin(x='sepal length (cm)', y='sepal width (cm)',
2931+
... gridsize=10, cmap='viridis')
28962932
"""
28972933
if reduce_C_function is not None:
28982934
kwds['reduce_C_function'] = reduce_C_function

0 commit comments

Comments
 (0)