.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "classes/base_classes/data/plot_hist2dmix.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_hist2dmix.py: ================== 2D Mixed-Histogram ================== Data on a regular two-dimensional grid which is the combination of an image and a histogram. The x-axis defines the bin edges along the second dimension. The y-axis defines the grid coordinates along the first dimension. .. 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[16] z: NX_FLOAT64[16,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 16 rows and 6 columns. 4. ``x`` has one more value than the second dimension of ``z`` since it contains the bin edges. .. GENERATED FROM PYTHON SOURCE LINES 37-67 .. image-sg:: /classes/base_classes/data/images/sphx_glr_plot_hist2dmix_001.png :alt: plot hist2dmix :srcset: /classes/base_classes/data/images/sphx_glr_plot_hist2dmix_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 = np.linspace(-3, 3, 16) nx = len(x) - 1 ny = len(y) z = np.zeros((ny, nx)) xx = np.linspace(-3, 3, 200) for i in range(ny): zi = (1 - xx / 2 + xx**5 + y[i] ** 3) * np.exp(-(xx**2) - y[i] ** 2) z[i, :], _ = np.histogram(xx, bins=x, weights=zi) # Plot import matplotlib.pyplot as plt # noqa E402 plt.style.use("_mpl-gallery-nogrid") fig, ax = plt.subplots() y_new = np.empty_like(y, shape=(len(y) + 1,)) y_new[0] = 2 * y[0] - y[1] y_new[1:-1] = (y[:-1] + y[1:]) / 2 y_new[-1] = 2 * y[-1] - y[-2] mesh = ax.pcolormesh(x, y_new, z, linewidth=0.7) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.035 seconds) .. _sphx_glr_download_classes_base_classes_data_plot_hist2dmix.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hist2dmix.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hist2dmix.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hist2dmix.zip `