{
    "cells": [
        {
            "cell_type": "code",
            "execution_count": 1,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:38:34.533682Z",
                    "start_time": "2020-09-13T15:38:32.683576Z",
                }
            },
            "outputs": [],
            "source": [
                "import numpy as np\n",
                "import matplotlib.pyplot as plt\n",
                "\n",
                "import mplhep as hep",
            ],
        },
        {"cell_type": "markdown", "metadata": {}, "source": ["## Style example"]},
        {
            "cell_type": "code",
            "execution_count": 2,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:38:35.005009Z",
                    "start_time": "2020-09-13T15:38:34.536276Z",
                }
            },
            "outputs": [
                {
                    "data": {
                        "image/png": "[encoded data, 82360 characters]\n",
                        "text/plain": ["<Figure size 720x720 with 1 Axes>"],
                    },
                    "metadata": {"needs_background": "light"},
                    "output_type": "display_data",
                }
            ],
            "source": [
                "x = np.random.uniform(0, 10, 240)\n",
                "y = np.random.normal(512, 112, 240)\n",
                "z = np.random.normal(0.5, 0.1, 240)\n",
                "\n",
                "plt.style.use([hep.style.ROOT, hep.style.firamath])\n",
                "\n",
                "f, ax = plt.subplots()\n",
                "ax.scatter(x,y, c=z, label='XSX')\n",
                "hep.cms.label(loc=0)\n",
                "\n",
                "plt.show()",
            ],
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": ["## 1D Histogram Options Example"],
        },
        {
            "cell_type": "code",
            "execution_count": 3,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:38:35.834639Z",
                    "start_time": "2020-09-13T15:38:35.008133Z",
                }
            },
            "outputs": [
                {
                    "data": {
                        "image/png": "[encoded data, 25748 characters]\n",
                        "text/plain": ["<Figure size 720x720 with 4 Axes>"],
                    },
                    "metadata": {"needs_background": "light"},
                    "output_type": "display_data",
                }
            ],
            "source": [
                "h, bins = np.histogram(np.random.normal(10,3,400), bins = 10)\n",
                "\n",
                "f, axs = plt.subplots(2,2, sharex=True, sharey=True)\n",
                "axs = axs.flatten()\n",
                "\n",
                'axs[0].set_title("Default", fontsize=18)\n',
                "hep.histplot(h, bins, ax=axs[0])\n",
                "\n",
                'axs[1].set_title("Plot Edges", fontsize=18)\n',
                "hep.histplot(h, bins, edges=True, ax=axs[1])\n",
                "\n",
                'axs[2].set_title("Plot Errorbars", fontsize=18)\n',
                "hep.histplot(h, bins, yerr=np.sqrt(h), ax=axs[2])\n",
                "\n",
                'axs[3].set_title("Filled Histogram", fontsize=18)\n',
                "hep.histplot(h, bins, histtype='fill', ax=axs[3])\n",
                "\n",
                "\n",
                "plt.tight_layout()\n",
                "plt.show()",
            ],
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": ["## Plotting multiple at once"],
        },
        {
            "cell_type": "code",
            "execution_count": 4,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:38:36.696875Z",
                    "start_time": "2020-09-13T15:38:35.836751Z",
                }
            },
            "outputs": [
                {
                    "data": {
                        "image/png": "[encoded data, 31784 characters]\n",
                        "text/plain": ["<Figure size 720x720 with 4 Axes>"],
                    },
                    "metadata": {"needs_background": "light"},
                    "output_type": "display_data",
                }
            ],
            "source": [
                "f, axs = plt.subplots(2,2, sharex=True, sharey=True)\n",
                "axs = axs.flatten()\n",
                "\n",
                'axs[0].set_title("Default Overlay", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, ax=axs[0])\n",
                "\n",
                'axs[1].set_title("Default Overlay w/ Errorbars", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, yerr=[np.sqrt(h), np.sqrt(1.5*h)], ax=axs[1])\n",
                "\n",
                "\n",
                'axs[2].set_title("Automatic Errorbars", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, yerr=True, ax=axs[2])\n",
                "\n",
                'axs[3].set_title("With Labels", fontsize=18)\n',
                'hep.histplot([h, 1.5*h], bins, yerr=True, ax=axs[3], label=["First", "Second"])\n',
                "\n",
                "axs[3].legend(fontsize=16)\n",
                "\n",
                "plt.tight_layout()\n",
                "plt.show()",
            ],
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": ["## 1D Histogram Stacking"],
        },
        {
            "cell_type": "code",
            "execution_count": 5,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:38:37.681516Z",
                    "start_time": "2020-09-13T15:38:36.699024Z",
                }
            },
            "outputs": [
                {
                    "data": {
                        "image/png": "[encoded data, 30852 characters]\n",
                        "text/plain": ["<Figure size 720x720 with 4 Axes>"],
                    },
                    "metadata": {"needs_background": "light"},
                    "output_type": "display_data",
                }
            ],
            "source": [
                "f, axs = plt.subplots(2,2, sharex=True, sharey=True)#, figsize=(10, 5))\n",
                "axs = axs.flatten()\n",
                "\n",
                'axs[0].set_title("Default", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, stack=True, ax=axs[0])\n",
                "\n",
                'axs[1].set_title("Plot Edges", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, edges=True, stack=True,ax=axs[1])\n",
                "\n",
                'axs[2].set_title("Plot Errorbars", fontsize=18)\n',
                "hep.histplot([h, 1.5*h], bins, yerr=[np.sqrt(h),np.sqrt(h)], stack=True, ax=axs[2])\n",
                "\n",
                'axs[3].set_title("Filled Histogram", fontsize=18)\n',
                "hep.histplot([1.5*h, h], bins, histtype='fill', stack=True, ax=axs[3])\n",
                "\n",
                "plt.tight_layout()\n",
                "plt.show()",
            ],
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": ["## 2D Histogram Example"],
        },
        {
            "cell_type": "code",
            "execution_count": 7,
            "metadata": {
                "ExecuteTime": {
                    "end_time": "2020-09-13T15:39:13.945654Z",
                    "start_time": "2020-09-13T15:39:13.485676Z",
                }
            },
            "outputs": [
                {
                    "data": {
                        "image/png": "[encoded data, 47356 characters]\n",
                        "text/plain": ["<Figure size 770.4x720 with 2 Axes>"],
                    },
                    "metadata": {"needs_background": "light"},
                    "output_type": "display_data",
                }
            ],
            "source": [
                "np.random.seed(0)\n",
                "xedges = np.arange(0, 11.5, 1.5)\n",
                "yedges = [0, 2, 3, 4, 6, 7]\n",
                "x = np.random.normal(5, 1.5, 100)\n",
                "y = np.random.normal(4, 1, 100)\n",
                "H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))\n",
                "\n",
                "fig, ax = plt.subplots()\n",
                "hep.hist2dplot(H, xedges, yedges, labels=True);",
            ],
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [],
        },
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python (def)",
            "language": "python",
            "name": "def",
        },
        "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.7.3",
        },
    },
    "nbformat": 4,
    "nbformat_minor": 2,
}
