From a7b7e5eee639db94f376ded553919c15525c29e1 Mon Sep 17 00:00:00 2001 From: Hasib Zunair Date: Sun, 27 Oct 2019 17:27:56 -0400 Subject: [PATCH 1/4] remove backend matplotlib.use('nbagg') and add ipympl --- AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb | 98 ++++++++++--- ...b-Part1-Figures_Subplots_and_layouts.ipynb | 46 +++--- ...tlib-Part2-Plotting_Methods_Overview.ipynb | 48 +++++- AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb | 22 ++- ...lib-Part4-Limits_Legends_and_Layouts.ipynb | 137 ++++++++++++++---- AnatomyOfMatplotlib-Part5-Artists.ipynb | 78 ++++++---- AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb | 47 +++--- README.md | 2 +- Test Install.ipynb | 22 +-- 9 files changed, 348 insertions(+), 152 deletions(-) diff --git a/AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb b/AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb index b2ff673..9d5f4ab 100644 --- a/AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb +++ b/AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -24,7 +27,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -43,7 +49,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -57,7 +66,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -71,7 +83,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -93,7 +108,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -112,7 +130,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -131,7 +152,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -143,7 +167,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -155,7 +182,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -170,7 +200,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -182,7 +215,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -201,9 +237,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "print(\"Shape of X:\", x.shape)\n", @@ -221,7 +255,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -246,7 +283,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -261,7 +301,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -271,27 +314,34 @@ "z = x * y\n", "print(z.shape)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb index bece646..5c821b8 100644 --- a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb +++ b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb @@ -5,6 +5,9 @@ "execution_count": null, "metadata": { "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, "slideshow": { "slide_type": "-" } @@ -87,33 +90,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If you are working interactively at an (I)python prompt, the GUI framework is not critical (mostly aesthetic) however when working in Jupyter we need to pick a backend that integrates with Jupyter (javascript) framework.\n", - "\n", - "To select the backend use ``matplotlib.use(\"backend_name\")``, in this case we want ``'nbagg'``\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "matplotlib.use('nbagg')\n", - "print(matplotlib.get_backend())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "which must be done *before* you `import matplotlib.pyplot as plt`.\n", - "\n", - "You can also set the backend via an 'ipython magic' ``%matplotlib backend_name``. In addition to setting the backend, the magic also calls `plt.ion()`, which puts Matplotlib in 'interacitve mode' (the inverse is `plt.ioff()`). In 'interactive mode' figures are shown (injected into the web page in the notebook) as soon as they are created. Otherwise, figures are not shown until you explicitly call `plt.show()`.\n", - "\n", - "\n", "In these tutorials we will mostly work in non-interactive mode for better control of when\n", "figures are shown in the notebooks.\n", - "This also better mimics the behavior you can expect in regular python scripts.\n" + "This also better mimics the behavior you can expect in regular python scripts." ] }, { @@ -436,7 +415,18 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/1.1-subplots_and_basic_plotting.py" + "# %load exercises/1.1-subplots_and_basic_plotting.py\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Try to reproduce the figure shown in images/exercise_1-1.png\n", + "\n", + "# Our data...\n", + "x = np.linspace(0, 10, 100)\n", + "y1, y2, y3 = np.cos(x), np.cos(x + 1), np.cos(x + 2)\n", + "names = ['Signal 1', 'Signal 2', 'Signal 3']\n", + "\n", + "# Can you figure out what to do next to plot x vs y1, y2, and y3 on one figure?\n" ] }, { @@ -475,9 +465,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb index 8239f9e..656642c 100644 --- a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb +++ b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb @@ -54,7 +54,6 @@ "from __future__ import print_function\n", "import numpy as np\n", "import matplotlib\n", - "matplotlib.use('nbagg')\n", "import matplotlib.pyplot as plt" ] }, @@ -234,7 +233,31 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/2.1-bar_and_fill_between.py" + "# %load exercises/2.1-bar_and_fill_between.py\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "np.random.seed(1)\n", + "\n", + "# Generate data...\n", + "y_raw = np.random.randn(1000).cumsum() + 15\n", + "x_raw = np.linspace(0, 24, y_raw.size)\n", + "\n", + "# Get averages of every 100 samples...\n", + "x_pos = x_raw.reshape(-1, 100).min(axis=1)\n", + "y_avg = y_raw.reshape(-1, 100).mean(axis=1)\n", + "y_err = y_raw.reshape(-1, 100).ptp(axis=1)\n", + "\n", + "bar_width = x_pos[1] - x_pos[0]\n", + "\n", + "# Make a made up future prediction with a fake confidence\n", + "x_pred = np.linspace(0, 30)\n", + "y_max_pred = y_avg[0] + y_err[0] + 2.3 * x_pred\n", + "y_min_pred = y_avg[0] - y_err[0] + 1.2 * x_pred\n", + "\n", + "# Just so you don't have to guess at the colors...\n", + "barcolor, linecolor, fillcolor = 'wheat', 'salmon', 'lightblue'\n", + "\n", + "# Now you're on your own!\n" ] }, { @@ -417,7 +440,22 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/2.2-vmin_vmax_imshow_and_colorbars.py" + "# %load exercises/2.2-vmin_vmax_imshow_and_colorbars.py\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "np.random.seed(1)\n", + "\n", + "# Generate random data with different ranges...\n", + "data1 = np.random.random((10, 10))\n", + "data2 = 2 * np.random.random((10, 10))\n", + "data3 = 3 * np.random.random((10, 10))\n", + "\n", + "# Set up our figure and axes...\n", + "fig, axes = plt.subplots(ncols=3, figsize=plt.figaspect(0.5))\n", + "fig.tight_layout() # Make the subplots fill up the figure a bit more...\n", + "cax = fig.add_axes([0.25, 0.1, 0.55, 0.03]) # Add an axes for the colorbar\n", + "\n", + "# Now you're on your own!\n" ] }, { @@ -462,9 +500,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb index e3c93fe..5a4c2a2 100644 --- a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb +++ b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb @@ -9,8 +9,8 @@ "# Let printing work the same in Python 2 and 3\n", "from __future__ import print_function\n", "# Turning on notebook plots -- just for use in jupyter notebooks.\n", + "%matplotlib inline\n", "import matplotlib\n", - "matplotlib.use('nbagg')\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] @@ -81,7 +81,10 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/3.1-colors.py\n" + "# %load exercises/3.1-colors.py\n", + "t = np.arange(0.0, 5.0, 0.2)\n", + "plt.plot(t, t, , t, t**2, , t, t**3, )\n", + "plt.show()\n" ] }, { @@ -151,7 +154,10 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/3.2-markers.py" + "# %load exercises/3.2-markers.py\n", + "t = np.arange(0.0, 5.0, 0.2)\n", + "plt.plot(t, t, , t, t**2, , t, t**3, )\n", + "plt.show()\n" ] }, { @@ -274,7 +280,11 @@ "metadata": {}, "outputs": [], "source": [ - "%load exercises/3.3-properties.py" + "# %load exercises/3.3-properties.py\n", + "t = np.arange(0.0, 5.0, 0.1)\n", + "a = np.exp(-t) * np.cos(2*np.pi*t)\n", + "plt.plot(t, a, )\n", + "plt.show()\n" ] }, { @@ -607,9 +617,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb index ec20839..e83d239 100644 --- a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb +++ b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -12,7 +15,6 @@ "\n", "# Import conventions we'll be using here. See Part 1\n", "import matplotlib\n", - "matplotlib.use('nbagg')\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] @@ -39,7 +41,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -66,7 +71,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -109,7 +117,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -142,7 +153,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -159,7 +173,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -187,7 +204,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -214,7 +234,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -242,19 +265,37 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ - "%load exercises/4.1-legends_and_scaling.py" + "# %load exercises/4.1-legends_and_scaling.py\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "plt.style.use('classic')\n", + "\n", + "# Try to reproduce the figure shown in images/exercise_4-1.png\n", + "# Here's the data and colors used.\n", + "\n", + "t = np.linspace(0, 2 * np.pi, 150)\n", + "x1, y1 = np.cos(t), np.sin(t)\n", + "x2, y2 = 2 * x1, 2 * y1\n", + "\n", + "colors = ['darkred', 'darkgreen']\n", + "\n", + "# Try to plot the two circles, scale the axes as shown and add a legend\n", + "# Hint: it's easiest to combine `ax.axis(...)` and `ax.margins(...)` to scale\n", + "# the axes\n" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", @@ -295,7 +336,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -326,7 +370,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -350,7 +397,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -376,7 +426,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -418,7 +471,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -440,7 +496,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -465,7 +524,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -515,18 +577,33 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ - "%load exercises/4.2-spines_ticks_and_subplot_spacing.py" + "# %load exercises/4.2-spines_ticks_and_subplot_spacing.py\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# Try to reproduce the figure shown in images/exercise_4.2.png\n", + "# This one is a bit trickier!\n", + "\n", + "# Here's the data...\n", + "data = [('dogs', 4, 4), ('frogs', -3, 1), ('cats', 1, 5), ('goldfish', -2, 2)]\n", + "animals, friendliness, popularity = zip(*data)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -544,23 +621,23 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part5-Artists.ipynb b/AnatomyOfMatplotlib-Part5-Artists.ipynb index 4da8545..8db1fbb 100644 --- a/AnatomyOfMatplotlib-Part5-Artists.ipynb +++ b/AnatomyOfMatplotlib-Part5-Artists.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -12,7 +15,6 @@ "from __future__ import print_function\n", "# Turning on inline plots -- just for use in ipython notebooks.\n", "import matplotlib\n", - "matplotlib.use('nbagg')\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] @@ -29,7 +31,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -146,7 +151,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -168,7 +176,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -189,7 +200,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -211,7 +225,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -239,7 +256,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -271,18 +291,33 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ - "%load exercises/5.1-goldstar.py" + "# %load exercises/5.1-goldstar.py\n", + "from matplotlib.collections import StarPolygonCollection\n", + "\n", + "fig, ax = plt.subplots(1, 1)\n", + "\n", + "collection = StarPolygonCollection(5,\n", + " offsets=[(0.5, 0.5)],\n", + " transOffset=ax.transData)\n", + "ax.add_collection(collection)\n", + "plt.show()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -296,36 +331,27 @@ "ax.add_collection(collection)\n", "plt.show()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb b/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb index 9ecb7d3..867a20d 100644 --- a/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb +++ b/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb @@ -4,12 +4,14 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ "import matplotlib\n", - "matplotlib.use('nbagg')\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] @@ -44,7 +46,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -71,7 +76,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -105,7 +113,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -173,7 +184,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -333,36 +347,27 @@ "\n", "plt.show()\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } diff --git a/README.md b/README.md index 726412c..5629a8f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ All you need is matplotlib (v1.5 or greater) and jupyter installed. You can use your favorite Python package installer for this: ```bash -conda install matplotlib jupyter +conda install matplotlib ipympl jupyter git clone https://github.com/matplotlib/AnatomyOfMatplotlib.git cd AnatomyOfMatplotlib jupyter notebook diff --git a/Test Install.ipynb b/Test Install.ipynb index 62a6fd6..08f5c00 100644 --- a/Test Install.ipynb +++ b/Test Install.ipynb @@ -4,13 +4,15 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ "from __future__ import print_function\n", "import matplotlib\n", - "matplotlib.use('nbagg')\n", "from matplotlib import pyplot as plt\n", "\n", "if matplotlib.__version__ < '1.5':\n", @@ -23,32 +25,30 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.12" + "pygments_lexer": "ipython3", + "version": "3.6.8" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } From 968ef29cfaa671114e7739f66867edd678d0e8ec Mon Sep 17 00:00:00 2001 From: Hasib Zunair Date: Sun, 27 Oct 2019 21:50:53 -0400 Subject: [PATCH 2/4] resolve issues in notebooks 1 and 3 --- ...b-Part1-Figures_Subplots_and_layouts.ipynb | 27 ++++++++++--------- AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb | 17 +++--------- Test Install.ipynb | 7 ----- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb index 5c821b8..cf932da 100644 --- a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb +++ b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb @@ -86,6 +86,13 @@ "print(matplotlib.get_backend())" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you are working interactively at an (I)python prompt, the GUI framework is not critical (mostly aesthetic) however when working in Jupyter we need to pick a backend that integrates with Jupyter (javascript) framework." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -415,18 +422,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/1.1-subplots_and_basic_plotting.py\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "\n", - "# Try to reproduce the figure shown in images/exercise_1-1.png\n", - "\n", - "# Our data...\n", - "x = np.linspace(0, 10, 100)\n", - "y1, y2, y3 = np.cos(x), np.cos(x + 1), np.cos(x + 2)\n", - "names = ['Signal 1', 'Signal 2', 'Signal 3']\n", - "\n", - "# Can you figure out what to do next to plot x vs y1, y2, and y3 on one figure?\n" + "%load exercises/1.1-subplots_and_basic_plotting.py" ] }, { @@ -447,6 +443,13 @@ "\n", "# Can you figure out what to do next to plot x vs y1, y2, and y3 on one figure?\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb index 5a4c2a2..ed6513e 100644 --- a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb +++ b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb @@ -9,7 +9,6 @@ "# Let printing work the same in Python 2 and 3\n", "from __future__ import print_function\n", "# Turning on notebook plots -- just for use in jupyter notebooks.\n", - "%matplotlib inline\n", "import matplotlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt" @@ -81,10 +80,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/3.1-colors.py\n", - "t = np.arange(0.0, 5.0, 0.2)\n", - "plt.plot(t, t, , t, t**2, , t, t**3, )\n", - "plt.show()\n" + "%load exercises/3.1-colors.py" ] }, { @@ -154,10 +150,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/3.2-markers.py\n", - "t = np.arange(0.0, 5.0, 0.2)\n", - "plt.plot(t, t, , t, t**2, , t, t**3, )\n", - "plt.show()\n" + "%load exercises/3.2-markers.py" ] }, { @@ -280,11 +273,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/3.3-properties.py\n", - "t = np.arange(0.0, 5.0, 0.1)\n", - "a = np.exp(-t) * np.cos(2*np.pi*t)\n", - "plt.plot(t, a, )\n", - "plt.show()\n" + "%load exercises/3.3-properties.py" ] }, { diff --git a/Test Install.ipynb b/Test Install.ipynb index 08f5c00..19fceb2 100644 --- a/Test Install.ipynb +++ b/Test Install.ipynb @@ -21,13 +21,6 @@ "plt.plot([1, 2, 3, 2, 1])\n", "plt.show()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 832a895ee817886fe8bc691269e80d18b62044de Mon Sep 17 00:00:00 2001 From: Hasib Zunair Date: Sun, 27 Oct 2019 22:07:38 -0400 Subject: [PATCH 3/4] keep canonical examples un-run in notebooks 2, 4 and 5 --- ...tlib-Part2-Plotting_Methods_Overview.ipynb | 43 +------------------ ...lib-Part4-Limits_Legends_and_Layouts.ipynb | 30 +------------ AnatomyOfMatplotlib-Part5-Artists.ipynb | 11 +---- 3 files changed, 5 insertions(+), 79 deletions(-) diff --git a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb index 656642c..6606926 100644 --- a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb +++ b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb @@ -233,31 +233,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/2.1-bar_and_fill_between.py\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "np.random.seed(1)\n", - "\n", - "# Generate data...\n", - "y_raw = np.random.randn(1000).cumsum() + 15\n", - "x_raw = np.linspace(0, 24, y_raw.size)\n", - "\n", - "# Get averages of every 100 samples...\n", - "x_pos = x_raw.reshape(-1, 100).min(axis=1)\n", - "y_avg = y_raw.reshape(-1, 100).mean(axis=1)\n", - "y_err = y_raw.reshape(-1, 100).ptp(axis=1)\n", - "\n", - "bar_width = x_pos[1] - x_pos[0]\n", - "\n", - "# Make a made up future prediction with a fake confidence\n", - "x_pred = np.linspace(0, 30)\n", - "y_max_pred = y_avg[0] + y_err[0] + 2.3 * x_pred\n", - "y_min_pred = y_avg[0] - y_err[0] + 1.2 * x_pred\n", - "\n", - "# Just so you don't have to guess at the colors...\n", - "barcolor, linecolor, fillcolor = 'wheat', 'salmon', 'lightblue'\n", - "\n", - "# Now you're on your own!\n" + "%load exercises/2.1-bar_and_fill_between.py" ] }, { @@ -440,22 +416,7 @@ "metadata": {}, "outputs": [], "source": [ - "# %load exercises/2.2-vmin_vmax_imshow_and_colorbars.py\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "np.random.seed(1)\n", - "\n", - "# Generate random data with different ranges...\n", - "data1 = np.random.random((10, 10))\n", - "data2 = 2 * np.random.random((10, 10))\n", - "data3 = 3 * np.random.random((10, 10))\n", - "\n", - "# Set up our figure and axes...\n", - "fig, axes = plt.subplots(ncols=3, figsize=plt.figaspect(0.5))\n", - "fig.tight_layout() # Make the subplots fill up the figure a bit more...\n", - "cax = fig.add_axes([0.25, 0.1, 0.55, 0.03]) # Add an axes for the colorbar\n", - "\n", - "# Now you're on your own!\n" + "%load exercises/2.2-vmin_vmax_imshow_and_colorbars.py" ] }, { diff --git a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb index e83d239..342da46 100644 --- a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb +++ b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb @@ -272,24 +272,7 @@ }, "outputs": [], "source": [ - "# %load exercises/4.1-legends_and_scaling.py\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "\n", - "plt.style.use('classic')\n", - "\n", - "# Try to reproduce the figure shown in images/exercise_4-1.png\n", - "# Here's the data and colors used.\n", - "\n", - "t = np.linspace(0, 2 * np.pi, 150)\n", - "x1, y1 = np.cos(t), np.sin(t)\n", - "x2, y2 = 2 * x1, 2 * y1\n", - "\n", - "colors = ['darkred', 'darkgreen']\n", - "\n", - "# Try to plot the two circles, scale the axes as shown and add a legend\n", - "# Hint: it's easiest to combine `ax.axis(...)` and `ax.margins(...)` to scale\n", - "# the axes\n" + "%load exercises/4.1-legends_and_scaling.py" ] }, { @@ -584,16 +567,7 @@ }, "outputs": [], "source": [ - "# %load exercises/4.2-spines_ticks_and_subplot_spacing.py\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "\n", - "# Try to reproduce the figure shown in images/exercise_4.2.png\n", - "# This one is a bit trickier!\n", - "\n", - "# Here's the data...\n", - "data = [('dogs', 4, 4), ('frogs', -3, 1), ('cats', 1, 5), ('goldfish', -2, 2)]\n", - "animals, friendliness, popularity = zip(*data)\n" + "%load exercises/4.2-spines_ticks_and_subplot_spacing.py" ] }, { diff --git a/AnatomyOfMatplotlib-Part5-Artists.ipynb b/AnatomyOfMatplotlib-Part5-Artists.ipynb index 8db1fbb..11e6e5c 100644 --- a/AnatomyOfMatplotlib-Part5-Artists.ipynb +++ b/AnatomyOfMatplotlib-Part5-Artists.ipynb @@ -298,16 +298,7 @@ }, "outputs": [], "source": [ - "# %load exercises/5.1-goldstar.py\n", - "from matplotlib.collections import StarPolygonCollection\n", - "\n", - "fig, ax = plt.subplots(1, 1)\n", - "\n", - "collection = StarPolygonCollection(5,\n", - " offsets=[(0.5, 0.5)],\n", - " transOffset=ax.transData)\n", - "ax.add_collection(collection)\n", - "plt.show()\n" + "%load exercises/5.1-goldstar.py" ] }, { From 514677107d4d6e7e648fbc0e04d9759af1ab7ed6 Mon Sep 17 00:00:00 2001 From: Hasib Zunair Date: Sun, 27 Oct 2019 23:31:52 -0400 Subject: [PATCH 4/4] added %matplotlib widget --- ...yOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb | 1 + AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb | 1 + AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb | 1 + ...omyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb | 1 + AnatomyOfMatplotlib-Part5-Artists.ipynb | 1 + AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb | 1 + Test Install.ipynb | 8 ++++++++ 7 files changed, 14 insertions(+) diff --git a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb index cf932da..74dc3d1 100644 --- a/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb +++ b/AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb @@ -81,6 +81,7 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib widget\n", "import matplotlib\n", "print(matplotlib.__version__)\n", "print(matplotlib.get_backend())" diff --git a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb index 6606926..754d2b2 100644 --- a/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb +++ b/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb @@ -53,6 +53,7 @@ "# Let's get our standard imports out of the way\n", "from __future__ import print_function\n", "import numpy as np\n", + "%matplotlib widget\n", "import matplotlib\n", "import matplotlib.pyplot as plt" ] diff --git a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb index ed6513e..c2ad156 100644 --- a/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb +++ b/AnatomyOfMatplotlib-Part3-HowToSpeakMPL.ipynb @@ -9,6 +9,7 @@ "# Let printing work the same in Python 2 and 3\n", "from __future__ import print_function\n", "# Turning on notebook plots -- just for use in jupyter notebooks.\n", + "%matplotlib widget\n", "import matplotlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt" diff --git a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb index 342da46..1b50237 100644 --- a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb +++ b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb @@ -14,6 +14,7 @@ "from __future__ import print_function\n", "\n", "# Import conventions we'll be using here. See Part 1\n", + "%matplotlib widget\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "import numpy as np" diff --git a/AnatomyOfMatplotlib-Part5-Artists.ipynb b/AnatomyOfMatplotlib-Part5-Artists.ipynb index 11e6e5c..71d1693 100644 --- a/AnatomyOfMatplotlib-Part5-Artists.ipynb +++ b/AnatomyOfMatplotlib-Part5-Artists.ipynb @@ -14,6 +14,7 @@ "# Let printing work the same in Python 2 and 3\n", "from __future__ import print_function\n", "# Turning on inline plots -- just for use in ipython notebooks.\n", + "%matplotlib widget\n", "import matplotlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt" diff --git a/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb b/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb index 867a20d..dfd60ec 100644 --- a/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb +++ b/AnatomyOfMatplotlib-Part6-mpl_toolkits.ipynb @@ -11,6 +11,7 @@ }, "outputs": [], "source": [ + "%matplotlib widget\n", "import matplotlib\n", "import numpy as np\n", "import matplotlib.pyplot as plt" diff --git a/Test Install.ipynb b/Test Install.ipynb index 19fceb2..a6b1dfe 100644 --- a/Test Install.ipynb +++ b/Test Install.ipynb @@ -12,6 +12,7 @@ "outputs": [], "source": [ "from __future__ import print_function\n", + "%matplotlib widget\n", "import matplotlib\n", "from matplotlib import pyplot as plt\n", "\n", @@ -21,6 +22,13 @@ "plt.plot([1, 2, 3, 2, 1])\n", "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {