.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/statistics/hexbin_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_statistics_hexbin_demo.py: ===================== Hexagonal binned plot ===================== `~.Axes.hexbin` is a 2D histogram plot, in which the bins are hexagons and the color represents the number of data points within each bin. .. GENERATED FROM PYTHON SOURCE LINES 9-36 .. code-block:: Python 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() .. image-sg:: /gallery/statistics/images/sphx_glr_hexbin_demo_001.png :alt: Hexagon binning, With a log color scale :srcset: /gallery/statistics/images/sphx_glr_hexbin_demo_001.png, /gallery/statistics/images/sphx_glr_hexbin_demo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-43 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axes.Axes.hexbin` / `matplotlib.pyplot.hexbin` .. _sphx_glr_download_gallery_statistics_hexbin_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hexbin_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hexbin_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_