.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "classes/base_classes/data/plot_hist1d.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_hist1d.py: ============ 1D Histogram ============ Histogram on a regular one-dimensional grid. The x-axis defines 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 = ["x"] @signal = "y" x: NX_INT64[8] y: NX_FLOAT64[7] Explanation: 1. ``@axes`` has one value which corresponds to the signal rank of one. 2. ``y`` is the default signal to be plotted versus ``x``. 3. ``x`` has one more value than ``y`` since it contains the bin edges. .. GENERATED FROM PYTHON SOURCE LINES 33-51 .. image-sg:: /classes/base_classes/data/images/sphx_glr_plot_hist1d_001.png :alt: plot hist1d :srcset: /classes/base_classes/data/images/sphx_glr_plot_hist1d_001.png :class: sphx-glr-single-img .. code-block:: Python # Data x = [0.5, 1.5, 2.5, 4, 5, 6.5, 7, 8] y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6] # Plot import numpy as np # noqa E402 import matplotlib.pyplot as plt # noqa E402 plt.style.use("_mpl-gallery") fig, ax = plt.subplots() centers = 0.5 * (np.array(x[:-1]) + np.array(x[1:])) widths = np.diff(x) ax.bar(centers, y, width=widths, edgecolor="k", linewidth=0.7) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.038 seconds) .. _sphx_glr_download_classes_base_classes_data_plot_hist1d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hist1d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hist1d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hist1d.zip `