{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# 1D Histogram\n\nHistogram on a regular one-dimensional grid.\n\nThe x-axis defines the bin edges. As illustrated in this example,\nthe bin widths are not necessarily identical.\n\n.. code::\n\n @NX_class = \"NXroot\"\n @default = \"scan1\"\n scan1:\n @NX_class = \"NXentry\"\n @default = \"data\"\n data:\n @NX_class = \"NXdata\"\n @axes = [\"x\"]\n @signal = \"y\"\n x: NX_INT64[8]\n y: NX_FLOAT64[7]\n\nExplanation:\n\n1. ``@axes`` has one value which corresponds to the signal rank of one.\n\n2. ``y`` is the default signal to be plotted versus ``x``.\n\n3. ``x`` has one more value than ``y`` since it contains the bin edges.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Data\nx = [0.5, 1.5, 2.5, 4, 5, 6.5, 7, 8]\ny = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6]\n\n# Plot\nimport numpy as np # noqa E402\nimport matplotlib.pyplot as plt # noqa E402\n\nplt.style.use(\"_mpl-gallery\")\n\nfig, ax = plt.subplots()\n\ncenters = 0.5 * (np.array(x[:-1]) + np.array(x[1:]))\nwidths = np.diff(x)\nax.bar(centers, y, width=widths, edgecolor=\"k\", linewidth=0.7)\n\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.16" } }, "nbformat": 4, "nbformat_minor": 0 }