Make a 2D hexagonal binning plot of points *x*, *y*. If *C* is *None*, the value of the hexagon is determined by the number of points in the hexagon. Otherwise, *C* specifies values at the coordinate (x[i], y[i]). For each hexagon, these values are reduced u
(self, x, y, C=None, gridsize=100, bins=None,
xscale='linear', yscale='linear', extent=None,
cmap=None, norm=None, vmin=None, vmax=None,
alpha=None, linewidths=None, edgecolors='face',
reduce_C_function=np.mean, mincnt=None, marginals=False,
colorizer=None, **kwargs)
| 5471 | @_preprocess_data(replace_names=["x", "y", "C"], label_namer="y") |
| 5472 | @_docstring.interpd |
| 5473 | def hexbin(self, x, y, C=None, gridsize=100, bins=None, |
| 5474 | xscale='linear', yscale='linear', extent=None, |
| 5475 | cmap=None, norm=None, vmin=None, vmax=None, |
| 5476 | alpha=None, linewidths=None, edgecolors='face', |
| 5477 | reduce_C_function=np.mean, mincnt=None, marginals=False, |
| 5478 | colorizer=None, **kwargs): |
| 5479 | """ |
| 5480 | Make a 2D hexagonal binning plot of points *x*, *y*. |
| 5481 | |
| 5482 | If *C* is *None*, the value of the hexagon is determined by the number |
| 5483 | of points in the hexagon. Otherwise, *C* specifies values at the |
| 5484 | coordinate (x[i], y[i]). For each hexagon, these values are reduced |
| 5485 | using *reduce_C_function*. |
| 5486 | |
| 5487 | Parameters |
| 5488 | ---------- |
| 5489 | x, y : array-like |
| 5490 | The data positions. *x* and *y* must be of the same length. |
| 5491 | |
| 5492 | C : array-like, optional |
| 5493 | If given, these values are accumulated in the bins. Otherwise, |
| 5494 | every point has a value of 1. Must be of the same length as *x* |
| 5495 | and *y*. |
| 5496 | |
| 5497 | gridsize : int or (int, int), default: 100 |
| 5498 | If a single int, the number of hexagons in the *x*-direction. |
| 5499 | The number of hexagons in the *y*-direction is chosen such that |
| 5500 | the hexagons are approximately regular. |
| 5501 | |
| 5502 | Alternatively, if a tuple (*nx*, *ny*), the number of hexagons |
| 5503 | in the *x*-direction and the *y*-direction. In the |
| 5504 | *y*-direction, counting is done along vertically aligned |
| 5505 | hexagons, not along the zig-zag chains of hexagons; see the |
| 5506 | following illustration. |
| 5507 | |
| 5508 | .. plot:: |
| 5509 | |
| 5510 | import numpy |
| 5511 | import matplotlib.pyplot as plt |
| 5512 | |
| 5513 | np.random.seed(19680801) |
| 5514 | n= 300 |
| 5515 | x = np.random.standard_normal(n) |
| 5516 | y = np.random.standard_normal(n) |
| 5517 | |
| 5518 | fig, ax = plt.subplots(figsize=(4, 4)) |
| 5519 | h = ax.hexbin(x, y, gridsize=(5, 3)) |
| 5520 | hx, hy = h.get_offsets().T |
| 5521 | ax.plot(hx[24::3], hy[24::3], 'ro-') |
| 5522 | ax.plot(hx[-3:], hy[-3:], 'ro-') |
| 5523 | ax.set_title('gridsize=(5, 3)') |
| 5524 | ax.axis('off') |
| 5525 | |
| 5526 | To get approximately regular hexagons, choose |
| 5527 | :math:`n_x = \\sqrt{3}\\,n_y`. |
| 5528 | |
| 5529 | bins : 'log' or int or sequence, default: None |
| 5530 | Discretization of the hexagon values. |