{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "name = '2017-05-05-matplotlib-subplots'\n", "title = 'More on subplots in matplotlib'\n", "tags = 'matplotlib'\n", "author = 'Denis Sergeev'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from nb_tools import connect_notebook_to_post\n", "from IPython.core.display import HTML, Image\n", "\n", "html = connect_notebook_to_post(name, title, tags, author)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Today we covered a very important part of `matplotlib` - how to create multiple subplots in one figure." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We touched upon the following topics:" ] }, { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OK, let's import the essentials:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the figure bigger by default and use non-white facecolor to see the edges:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "plt.rcParams['figure.facecolor'] = '0.9'\n", "plt.rcParams['figure.figsize'] = (9, 6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Matplotlib Axes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Axes are very similar to subplots but allow placement of plots at any location in the figure. So if we want to put a smaller plot inside a bigger one we do so with axes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As an argument, `plt.axes()` takes a sequence **[Left, Bottom, Width, Height]**" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "txt_kw = dict(ha='left', va='center', size=16, alpha=.5)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "This post was written as an IPython (Jupyter) notebook. You can view or download it using\n", " nbviewer.
\n", " " ], "text/plain": [ "