diff --git a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb index 534fc87..633c685 100644 --- a/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb +++ b/AnatomyOfMatplotlib-Part4-Limits_Legends_and_Layouts.ipynb @@ -3,9 +3,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function\n", @@ -38,9 +36,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=plt.figaspect(0.5))\n", @@ -65,9 +61,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, (ax1, ax2) = plt.subplots(1, 2, figsize=plt.figaspect(0.5))\n", @@ -108,9 +102,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, axes = plt.subplots(nrows=3)\n", @@ -141,9 +133,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Good -- setting limits after plotting is done\n", @@ -158,9 +148,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# Bad -- Setting limits before plotting is done\n", @@ -186,9 +174,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", @@ -213,9 +199,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(1, 1)\n", @@ -241,20 +225,33 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "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", @@ -294,9 +291,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", @@ -315,9 +310,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "A commonly-asked question is \"How do I plot non-numerical categories?\"\n", + "A commonly-asked question is \"How do I plot categories?\"\n", " \n", - "Currently, the easiest way to do this is to \"fake\" the x-values and then change the tick labels to reflect the category.\n", + "Starting in version 2.0, just like any other data. \n", "\n", "For example:" ] @@ -325,18 +320,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "data = [('apples', 2), ('oranges', 3), ('peaches', 1)]\n", "fruit, value = zip(*data)\n", "\n", "fig, ax = plt.subplots()\n", - "x = np.arange(len(fruit))\n", - "ax.bar(x, value, align='center', color='gray')\n", - "ax.set(xticks=x, xticklabels=fruit)\n", + "ax.bar(fruit, value, align='center', color='gray')\n", "plt.show()" ] }, @@ -351,9 +342,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, axes = plt.subplots(2, 2, figsize=(9, 9))\n", @@ -377,9 +366,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def example_plot(ax):\n", @@ -419,9 +406,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)\n", @@ -441,9 +426,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax1 = plt.subplots(1, 1)\n", @@ -466,9 +449,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", @@ -516,9 +497,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "%load exercises/4.2-spines_ticks_and_subplot_spacing.py" @@ -527,9 +506,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -546,23 +523,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.5" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 }