Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Explain gridsize in hexbin() #24193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4715,7 +4715,31 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
the hexagons are approximately regular.

Alternatively, if a tuple (*nx*, *ny*), the number of hexagons
in the *x*-direction and the *y*-direction.
in the *x*-direction and the *y*-direction. In the
*y*-direction, counting is done along vertically aligned
hexagons, not along the zig-zag chains of hexagons; see the
following illustration.

.. plot::

import numpy
import matplotlib.pyplot as plt

np.random.seed(19680801)
n= 300
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)

fig, ax = plt.subplots(figsize=(4, 4))
h = ax.hexbin(x, y, gridsize=(5, 3))
hx, hy = h.get_offsets().T
ax.plot(hx[24::3], hy[24::3], 'ro-')
ax.plot(hx[-3:], hy[-3:], 'ro-')
ax.set_title('gridsize=(5, 3)')
ax.axis('off')

To get approximately regular hexagons, choose
:math:`n_x = \\sqrt{3}\\,n_y`.

bins : 'log' or int or sequence, default: None
Discretization of the hexagon values.
Expand Down