Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.plot.hexbin#

DataFrame.plot.hexbin(x,y,C=None,reduce_C_function=None,gridsize=None,**kwargs)[source]#

Generate a hexagonal binning plot.

Generate a hexagonal binning plot ofx versusy. IfC isNone(the default), this is a histogram of the number of occurrencesof the observations at(x[i],y[i]).

IfC is specified, specifies values at given coordinates(x[i],y[i]). These values are accumulated for each hexagonalbin and then reduced according toreduce_C_function,having as default the NumPy’s mean function (numpy.mean()).(IfC is specified, it must also be a 1-D sequenceof the same length asx andy, or a column label.)

Parameters:
xint or str

The column label or position for x points.

yint or str

The column label or position for y points.

Cint or str, optional

The column label or position for the value of(x, y) point.

reduce_C_functioncallable, defaultnp.mean

Function of one argument that reduces all the values in a bin toa single number (e.g.np.mean,np.max,np.sum,np.std).

gridsizeint or tuple of (int, int), default 100

The number of hexagons in the x-direction.The corresponding number of hexagons in the y-direction ischosen in a way that the hexagons are approximately regular.Alternatively, gridsize can be a tuple with two elementsspecifying the number of hexagons in the x-direction and they-direction.

**kwargs

Additional keyword arguments are documented inDataFrame.plot().

Returns:
matplotlib.AxesSubplot

The matplotlibAxes on which the hexbin is plotted.

See also

DataFrame.plot

Make plots of a DataFrame.

matplotlib.pyplot.hexbin

Hexagonal binning plot using matplotlib, the matplotlib function that is used under the hood.

Examples

The following examples are generated with random data froma normal distribution.

>>>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)
../../_images/pandas-DataFrame-plot-hexbin-1.png

The next example usesC andnp.sum asreduce_C_function.Note that‘observations’ values ranges from 1 to 5 but the resultplot shows values up to more than 25. This is because of thereduce_C_function.

>>>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")
../../_images/pandas-DataFrame-plot-hexbin-2.png

[8]ページ先頭

©2009-2025 Movatter.jp