{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### non ipympl backends\n", "\n", "every function in this library should work with any interactive matplotlib backend. Although the functions from `mpl_interactions.jupyter` assume that you are in a notebook context in order to display the sliders." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# NBVAL_SKIP\n", "%matplotlib qt5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "import matplotlib.pyplot as plt\n", "from mpl_interactions import interactive_plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The below cell will display the sliders in the notebook but a separate matplotlib window will pop up. An important caveat is that the performance of `interactive_plot` seems to be significantly worse with a non-ipympl backend." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = np.linspace(0, np.pi, 100)\n", "τ = np.linspace(1, 10, 100)\n", "β = np.linspace(1, 10, 100)\n", "\n", "\n", "def f(x, τ, β):\n", " return np.sin(x * τ) * x ** β\n", "\n", "\n", "fig, ax = plt.subplots()\n", "controls = interactive_plot(x, f, τ=τ, β=β)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### generic submodule\n", "\n", "`mpl_interactions.generic` contains functions that will work in any matplotlib context. So for example the below code will work in the notebook or from a script" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from mpl_interactions.generic import heatmap_slicer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = np.linspace(0, np.pi, 100)\n", "y = np.linspace(0, 10, 200)\n", "X, Y = np.meshgrid(x, y)\n", "data1 = np.sin(X) + np.exp(np.cos(Y))\n", "data2 = np.cos(X) + np.exp(np.sin(Y))\n", "fig, axes = heatmap_slicer(\n", " x,\n", " y,\n", " (data1, data2),\n", " slices=\"both\",\n", " heatmap_names=(\"dataset 1\", \"dataset 2\"),\n", " labels=(\"Some wild X variable\", \"Y axis\"),\n", " interaction_type=\"move\",\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 }