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

Skip to content

Commit 40cd821

Browse files
authored
Merge pull request #24193 from timhoffm/doc-hexbin-grid
DOC: Explain gridsize in hexbin()
2 parents 23730b4 + 91dd808 commit 40cd821

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4715,7 +4715,31 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
47154715
the hexagons are approximately regular.
47164716
47174717
Alternatively, if a tuple (*nx*, *ny*), the number of hexagons
4718-
in the *x*-direction and the *y*-direction.
4718+
in the *x*-direction and the *y*-direction. In the
4719+
*y*-direction, counting is done along vertically aligned
4720+
hexagons, not along the zig-zag chains of hexagons; see the
4721+
following illustration.
4722+
4723+
.. plot::
4724+
4725+
import numpy
4726+
import matplotlib.pyplot as plt
4727+
4728+
np.random.seed(19680801)
4729+
n= 300
4730+
x = np.random.standard_normal(n)
4731+
y = np.random.standard_normal(n)
4732+
4733+
fig, ax = plt.subplots(figsize=(4, 4))
4734+
h = ax.hexbin(x, y, gridsize=(5, 3))
4735+
hx, hy = h.get_offsets().T
4736+
ax.plot(hx[24::3], hy[24::3], 'ro-')
4737+
ax.plot(hx[-3:], hy[-3:], 'ro-')
4738+
ax.set_title('gridsize=(5, 3)')
4739+
ax.axis('off')
4740+
4741+
To get approximately regular hexagons, choose
4742+
:math:`n_x = \\sqrt{3}\\,n_y`.
47194743
47204744
bins : 'log' or int or sequence, default: None
47214745
Discretization of the hexagon values.

0 commit comments

Comments
 (0)