[ Web Proxy ]
URL:
Viewing: https://matplotlib.org/stable/api/_as_gen/../../gallery/misc/../misc/../statistics/hexbin_demo.html [Back]  [Original]

Hexagonal binned plot — Matplotlib 3.11.2 documentation
Back to top
Search the docs ...:

Hexagonal binned plot#

hexbin is a 2D histogram plot, in which the bins are hexagons and the color represents the number of data points within each bin.

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

n = 100_000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xlim = x.min(), x.max()
ylim = y.min(), y.max()

fig, (ax0, ax1) = plt.subplots(ncols=2, sharey=True, figsize=(9, 4))

hb = ax0.hexbin(x, y, gridsize=50, cmap='inferno')
ax0.set(xlim=xlim, ylim=ylim)
ax0.set_title("Hexagon binning")
cb = fig.colorbar(hb, ax=ax0, label='counts')

hb = ax1.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
ax1.set(xlim=xlim, ylim=ylim)
ax1.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax1, label='counts')

plt.show()
Hexagon binning, With a log color scale [Hexagon binning, With a log color scale]

Tags: plot-type: histogram plot-type: hexbin domain: statistics

References

The use of the following functions, methods, classes and modules is shown in this example:

Total running time of the script: (0 minutes 1.062 seconds)

Gallery generated by Sphinx-Gallery


Web Proxy Viewer  |  New URL  |  Original Page