.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "classes/base_classes/data/plot_hist2d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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_classes_base_classes_data_plot_hist2d.py: ============ 2D Histogram ============ Histogram on a regular two-dimensional grid. The x-axis and y-axis define the bin edges. As illustrated in this example, the bin widths are not necessarily identical. .. code:: @NX_class = "NXroot" @default = "scan1" scan1: @NX_class = "NXentry" @default = "data" data: @NX_class = "NXdata" @axes = ["y", "x"] @signal = "z" x: NX_FLOAT64[7] y: NX_FLOAT64[9] z: NX_FLOAT64[8,6] Explanation: 1. ``@axes`` has two values which corresponds to the signal rank of two. 2. ``z`` is the default signal to be plotted versus ``x`` and ``y``. 3. ``z`` has 6 rows and 8 columns. 4. ``y`` has one more value than the first dimension of ``z`` since it contains the bin edges. 5. ``x`` has one more value than the second dimension of ``z`` since it contains the bin edges. .. GENERATED FROM PYTHON SOURCE LINES 38-61 .. image-sg:: /classes/base_classes/data/images/sphx_glr_plot_hist2d_001.png :alt: plot hist2d :srcset: /classes/base_classes/data/images/sphx_glr_plot_hist2d_001.png :class: sphx-glr-single-img .. code-block:: Python # Data import numpy as np x = [-3.0, -2.5, -1.0, 0.0, 1.0, 2.5, 3.0] y = [-3.0, -2.8, -1.3, -0.75, 0.0, 0.1, 1.5, 2.25, 3.0] xx = np.linspace(-3, 3, 200) yy = np.linspace(-3, 3, 200) xx, yy = np.meshgrid(xx, yy) zz = (1 - xx / 2 + xx**5 + yy**3) * np.exp(-(xx**2) - yy**2) z, _, _ = np.histogram2d(yy.flatten(), xx.flatten(), bins=[y, x], weights=zz.flatten()) # Plot import matplotlib.pyplot as plt # noqa E402 plt.style.use("_mpl-gallery-nogrid") fig, ax = plt.subplots() mesh = ax.pcolormesh(x, y, z, edgecolor="k", linewidth=0.7, shading="flat") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.079 seconds) .. _sphx_glr_download_classes_base_classes_data_plot_hist2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hist2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hist2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hist2d.zip `