{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Hist" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib ipympl\n", "import ipywidgets as widgets\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "from mpl_interactions import interactive_hist" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "limitations: \n", " \n", " 1. zorder may be funky (this is not calling ax.hist internally)\n", " 2. only vertical histograms\n", " 3. no stacked histograms\n", " 4. currently no labels are possible\n", " - this one may actually be worth fixing\n", " 5. only allows stretching the axis limits - no auto scaling\n", " 7. the axis relimming is a bit hacky, may not be exactly equivalent to what you'd get by call plt.hist\n", " \n", "There are some limitations to the current approach that could be worked around. But that would require a high amount of effort and all of these limitations should be solved by https://github.com/matplotlib/matplotlib/pull/18275 which be released with matplotlib version 3.4\n", "\n", "\n", "This accepts the following arguments that are passed through to `np.histogram`. Here they are with their default values:\n", "- `density = False`\n", "- `bins = 'auto'`\n", "- `weight = None`\n", "\n", "`f` must return " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def f(loc, scale):\n", " return np.random.randn(10000) * scale + loc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "controls = interactive_hist(f, loc=(0, 10, 100), scale=(0.5, 5))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig2, ax2 = plt.subplots()\n", "controls2 = interactive_hist(\n", " f, loc=(0, 10, 100), scale=(0.5, 5), bins=100, density=True\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }