.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/matplotlib/plot_main02_hexbin.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_matplotlib_plot_main02_hexbin.py: 02. ``mpl.hexbin`` ------------------------ Make a 2D hexagonal binning plot of points x, y. .. GENERATED FROM PYTHON SOURCE LINES 8-54 .. image-sg:: /_examples/matplotlib/images/sphx_glr_plot_main02_hexbin_001.png :alt: Hexagon binning, With a log color scale :srcset: /_examples/matplotlib/images/sphx_glr_plot_main02_hexbin_001.png :class: sphx-glr-single-img .. code-block:: default :lineno-start: 9 import pandas as pd import numpy as np import matplotlib.pyplot as plt # constant n = 100000 # Fixing random state for reproducibility np.random.seed(19680801) # Generate data x = np.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) z = None # Compute limits xmin = x.min() xmax = x.max() ymin = y.min() ymax = y.max() # Display hexagon binning (linear) fig, axs = plt.subplots(ncols=2, sharey=True, figsize=(7, 4)) fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93) ax = axs[0] hb = ax.hexbin(x, y, C=z, cmap='coolwarm', reduce_C_function=np.median) ax.axis([xmin, xmax, ymin, ymax]) ax.set_title("Hexagon binning") ax.invert_xaxis() cb = fig.colorbar(hb, ax=ax) cb.set_label('N=median') # Display hexagon binning (log) ax = axs[1] hb = ax.hexbin(x, y, C=z, gridsize=50, bins='log', cmap='coolwarm', reduce_C_function=np.median) ax.axis([xmin, xmax, ymin, ymax]) ax.set_title("With a log color scale") ax.invert_xaxis() cb = fig.colorbar(hb, ax=ax) cb.set_label('log10(N)') # Show plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.853 seconds) .. _sphx_glr_download__examples_matplotlib_plot_main02_hexbin.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main02_hexbin.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main02_hexbin.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_