mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
437 lines
147 KiB
Python
437 lines
147 KiB
Python
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"<!--BOOK_INFORMATION-->\n",
|
||
|
"<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PDSH-cover-small.png\">\n",
|
||
|
"*This notebook contains an excerpt from the [Python Data Science Handbook](http://shop.oreilly.com/product/0636920034919.do) by Jake VanderPlas; the content is available [on GitHub](https://github.com/jakevdp/PythonDataScienceHandbook).*\n",
|
||
|
"\n",
|
||
|
"*The text is released under the [CC-BY-NC-ND license](https://creativecommons.org/licenses/by-nc-nd/3.0/us/legalcode), and code is released under the [MIT license](https://opensource.org/licenses/MIT). If you find this content useful, please consider supporting the work by [buying the book](http://shop.oreilly.com/product/0636920034919.do)!*\n",
|
||
|
"\n",
|
||
|
"*No changes were made to the contents of this notebook from the original.*"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"<!--NAVIGATION-->\n",
|
||
|
"< [Customizing Colorbars](04.07-Customizing-Colorbars.ipynb) | [Contents](Index.ipynb) | [Text and Annotation](04.09-Text-and-Annotation.ipynb) >"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Multiple Subplots"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Sometimes it is helpful to compare different views of data side by side.\n",
|
||
|
"To this end, Matplotlib has the concept of *subplots*: groups of smaller axes that can exist together within a single figure.\n",
|
||
|
"These subplots might be insets, grids of plots, or other more complicated layouts.\n",
|
||
|
"In this section we'll explore four routines for creating subplots in Matplotlib."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"%matplotlib inline\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"plt.style.use('seaborn-white')\n",
|
||
|
"import numpy as np"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## ``plt.axes``: Subplots by Hand\n",
|
||
|
"\n",
|
||
|
"The most basic method of creating an axes is to use the ``plt.axes`` function.\n",
|
||
|
"As we've seen previously, by default this creates a standard axes object that fills the entire figure.\n",
|
||
|
"``plt.axes`` also takes an optional argument that is a list of four numbers in the figure coordinate system.\n",
|
||
|
"These numbers represent ``[left, bottom, width, height]`` in the figure coordinate system, which ranges from 0 at the bottom left of the figure to 1 at the top right of the figure.\n",
|
||
|
"\n",
|
||
|
"For example, we might create an inset axes at the top-right corner of another axes by setting the *x* and *y* position to 0.65 (that is, starting at 65% of the width and 65% of the height of the figure) and the *x* and *y* extents to 0.2 (that is, the size of the axes is 20% of the width and 20% of the height of the figure):"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFS5JREFUeJzt3V9olFcexvFndBzjOpEgVQrbJKZqEBSsSaFgCQbqgLAp\n9V90NEwuFAu9KsSbemESL0LUUi9KzEW7EDG1mRJquxJ2tbgTvdAiIRg1W0iLG2x2izBYdZIYMyY5\neyGZbRqdN5Nm8mZOvp8bnffMnPzmII9vzvue83qMMUYAAGsscLsAAMDMItgBwD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S1a9dq165devfdd1VaWiq/\n3//SegKBwAvvKppLC8UIdsAyM7GYyakf6fm89YkTJ/T999+/9Dmryfq4ePGiHj16pEOHDumzzz5T\nW1ubvv3225T6yMnJUV5engoKCuT1elVSUjLpbNypj56eHl25ckWRSESRSEQPHjzQpUuXXvh9kkll\nbNONYAcsk+z5qL9dzBSPx9XR0aE33ngj5X6kqT1nNVkfoVBIX3/9tc6ePav3339fZWVl2r59e0p9\n5Obm6smTJ4mLoZ2dnVqzZk1KfWRnZ2vJkiXy+XyJ30RisdgLv89v/f63jFTGNt24jx2wzEwsZnLq\nZ6rPWXWqZSa+T11dnaqqqiRJmzZt0pYtW1LuY/zuHp/Pp7y8PO3YscOxrvF5+OmMbbp5TLLJrRnw\nn//8R++8847++c9/6rXXXkvnjwIAa/yR7HQ8YzfGqLa2Vj09PfL5fKqrq1Nubm6i/fbt2zpx4oQk\n6ZVXXtHHH3/80l/LAAD
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10bd88240>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ax1 = plt.axes() # standard axes\n",
|
||
|
"ax2 = plt.axes([0.65, 0.65, 0.2, 0.2])"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"The equivalent of this command within the object-oriented interface is ``fig.add_axes()``. Let's use this to create two vertically stacked axes:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEBCAYAAACXArmGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X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H0aNouJ/gwZxTRdWdgkJwKZNwNatgK2t6GjkQ6EAvv4a+PNPOuEy\nZ1olBU9PT83Zf1paGtzd3TWP5ebmwtfXF/n5+ZAkCUePHkVTA+weu36dqhvGxgItW+r96c3CZ59R\nc5GPPhIdCTMFR44A4eHAt9/ySdazPNz1nJBAIxTmSquJZh8fHxw6dAj+/v4AgOjoaOzatQv5+flQ\nq9UYP348goKCYGdnh7Zt26Jjx456DbqoiCZ+AgNpkxp7NisregO3akVL6x78dzH2lOxsuqpcvdo8\nKwDoS82a1JirWzfAzc20C2w+j0KSxGx3unLlCry9vZGUlAQXF5dy/d2xY4GLF+mMxsrKQAGakbQ0\nKp534IBlLi1kL1ZURMsu33mHlnSzl9u2jXpJnDwJVK0qOprn0+Z71uQ2r33zDW0qWb+eE0JZtWwJ\nREfTiqRSU0GMAaBe4JUrA5MmiY7EdAwcSKMUw4aZ38SzSSWF06dp3fT27aZdw12EsDCqAzVyJJfC\nYI/s3Enj4/HxtDOelV10NHDzJlVQMCcm8zbIy6PMvGABD4FoQ6Ggzm1pacCKFaKjYXKQlUW9yjdu\nlPcQiFzZ2NBrN38+daAzFyaTFMaOpc00wcGiIzFdFSoAW7bQOvQTJ0RHw0QqLATefReYOBFo1050\nNKbL1RVYuZIWcdy8KTo
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10e296748>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig = plt.figure()\n",
|
||
|
"ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4],\n",
|
||
|
" xticklabels=[], ylim=(-1.2, 1.2))\n",
|
||
|
"ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4],\n",
|
||
|
" ylim=(-1.2, 1.2))\n",
|
||
|
"\n",
|
||
|
"x = np.linspace(0, 10)\n",
|
||
|
"ax1.plot(np.sin(x))\n",
|
||
|
"ax2.plot(np.cos(x));"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"We now have two axes (the top with no tick labels) that are just touching: the bottom of the upper panel (at position 0.5) matches the top of the lower panel (at position 0.1 + 0.4)."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## ``plt.subplot``: Simple Grids of Subplots\n",
|
||
|
"\n",
|
||
|
"Aligned columns or rows of subplots are a common-enough need that Matplotlib has several convenience routines that make them easy to create.\n",
|
||
|
"The lowest level of these is ``plt.subplot()``, which creates a single subplot within a grid.\n",
|
||
|
"As you can see, this command takes three integer arguments—the number of rows, the number of columns, and the index of the plot to be created in this scheme, which runs from the upper left to the bottom right:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X1QVPX+B/D3UVxA0RxJYywhK4GSSV3QjKJM3bLCZ1Ae\nWkwau7fpNpZNmaWItzHUSesWMveapuMjXSY1hkqZBjRLM3wAo6a1lLFNowiBBUFW8Pv7gx+bKw+7\nZ/csd/fr+zXTXD3n7Od8uG/247LsOV9FCCFARETS6PW/boCIiLTFwU5EJBkOdiIiyXCwExFJhoOd\niEgyHOxERJJxarCXlZXBaDR22F5UVISEhAQkJSUhLy9P8+bIs5irvJjtjc3P0QEbN27EJ598gn79\n+tltb2lpwapVq7B79274+/sjOTkZkyZNwqBBgzzWLGmHucqL2ZLDV+xhYWFYv359h+1nzpxBWFgY\ngoKC0KdPH0RHR6OkpMQjTZL2mKu8mC05HOwGgw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rV69G\nYGAgYmNj8eKLLyIsLMx2nLP1OqMoSqfbhRAoLS3Fk08+qaqer/PFbNX0B9yY2fpirmrqAV6Yqwa3\nNOiWJ+478fzzz7t1M6633nrL7n4a7tK63ldffSUiIyO96qZCnqx1LWarntZZ8Dmrnrfl6nPvsQNA\neno6Tpw40eGWpM6orq5GcXExoqKiNOlF63oAsHfvXsTGxtpdNXijYLZyYq49yycHu16vxyOPPIIN\nGzaofuzFixfx6quvIjQ
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10bec31d0>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"for i in range(1, 7):\n",
|
||
|
" plt.subplot(2, 3, i)\n",
|
||
|
" plt.text(0.5, 0.5, str((2, 3, i)),\n",
|
||
|
" fontsize=18, ha='center')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"The command ``plt.subplots_adjust`` can be used to adjust the spacing between these plots.\n",
|
||
|
"The following code uses the equivalent object-oriented command, ``fig.add_subplot()``:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xtwk3W6B/BvoKStBJZpBRlcWhF7cakHSAHZKsqlWT1Y\n7i2krSlYBncdZkdlzwpoKeU4tcCurGctnSN6tqzlUre74DLdI3acFmSFxXJpoTqmih2MaN1KL+k9\npfzOH53mbExpbm9I8sv3M+NI3/fN8z7Jt3naJnnfVyWEECAiImmM8HUDRESkLA52Ii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pUgADb9BcvHgR\nWq0WP/7xj4fcx8iRI5GTk4PNmzfjySefxJIlS9DS0oJDhw4hJCQE27Zts27rTD131NbWIioqChMn\nTlSsZiAKxLxd6W8Q8w7MrF2pN8hXWfv1YH/44YehUqlw7tw5a/jV1dVQqVQwm802Bzf8q8Hwz507\nhxdffBEFBQXDDuKlS5daDz7YtWsXwsPDkZSUhOeeew7R0dHW7ZytNxSVSjXkciEEampq8MQTT7hU\nT0aBmLcr/QHMe1AgZu1KPcDHWbt9IgMneXo+iY0bN3p0Mq5XXnnF5pwYnlK63t///ncRHx/v9smC\nlDxXjBKY9/BkyptZD8+XWfv1a+wAkJ2djQsXLtidVtQZ169fR1VVFRISEhTpRel6APDuu+8iKSnJ\n5si/YMa8gwez9h6/H+xarRYLFizAvn37XL5tc3MzXnjhBURFRSnSi9L1TCYTKioqrEf4EfMOJsza\ne/x+sANAbm4uKioqXP7
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10be83ac8>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig = plt.figure()\n",
|
||
|
"fig.subplots_adjust(hspace=0.4, wspace=0.4)\n",
|
||
|
"for i in range(1, 7):\n",
|
||
|
" ax = fig.add_subplot(2, 3, i)\n",
|
||
|
" ax.text(0.5, 0.5, str((2, 3, i)),\n",
|
||
|
" fontsize=18, ha='center')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"We've used the ``hspace`` and ``wspace`` arguments of ``plt.subplots_adjust``, which specify the spacing along the height and width of the figure, in units of the subplot size (in this case, the space is 40% of the subplot width and height)."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## ``plt.subplots``: The Whole Grid in One Go\n",
|
||
|
"\n",
|
||
|
"The approach just described can become quite tedious when creating a large grid of subplots, especially if you'd like to hide the x- and y-axis labels on the inner plots.\n",
|
||
|
"For this purpose, ``plt.subplots()`` is the easier tool to use (note the ``s`` at the end of ``subplots``). Rather than creating a single subplot, this function creates a full grid of subplots in a single line, returning them in a NumPy array.\n",
|
||
|
"The arguments are the number of rows and number of columns, along with optional keywords ``sharex`` and ``sharey``, which allow you to specify the relationships between different axes.\n",
|
||
|
"\n",
|
||
|
"Here we'll create a $2 \\times 3$ grid of subplots, where all axes in the same row share their y-axis scale, and all axes in the same column share their x-axis scale:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFBlJREFUeJzt3V9MVGcax/HfKA5YRkNIMSYtIPVPTDTpCk2a2BBJ6iQm\nZbOiYEfJzIXGTfZqE3uzXgj0goA260WDXOw2oZFSpyFLt4akumkGuNCNIUZQ2mTaGMKSbUwmVgUR\nQei7F4SpSOXMzJkps2++nxvlHOblmTzJzzMH3/N4jDFGAABrrFntAgAA6UWwA4BlCHYAsAzBDgCW\nIdgBwDIEOwBYJqFgHx4eVjAYXHY8EomotrZWgUBA3d3daS8OAJC8HKdv+OSTT/TVV18pPz9/yfG5\nuTm1traqp6dHubm5Onr0qN59910VFhZmrFgAgDPHK/bS0lJduHBh2fG7d++qtLRUPp9P69atU0VF\nhQYHBzNSJAAgcY7B7vf7tXbt2mXHHz9+rA0bNsS/zs/P1+TkZHqrAwAkzfFWzMv4fD49fvw4/vXU\n1JQ2bty47PuePn2qkZERFRUV/eo/EPjtzM/PKxaLaffu3crLy3O1Fn3NHunsq0Rvs4WbviYc7C8+\nUmbr1q0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6ampuJfPx/q0WhU/f39ikQiikQiun//vq5evZq5agEAjhyDvby8XAMDA5KkoaEh7dixI35u\nw4YNWr9+vbxerzwejwoLCzUxMZG5agEAjhxvxfj9fl27dk2BQECS1NLSsmTu6ZEjR3Ts2DF5vV6V\nlJSopqYm40UDAF7OMdg
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x1023b3828>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"fig, ax = plt.subplots(2, 3, sharex='col', sharey='row')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Note that by specifying ``sharex`` and ``sharey``, we've automatically removed inner labels on the grid to make the plot cleaner.\n",
|
||
|
"The resulting grid of axes instances is returned within a NumPy array, allowing for convenient specification of the desired axes using standard array indexing notation:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X9Q1HX+B/DnIiygizk4Ev4ApBKdsLNQ07woK7dzkgqS\nzdVtITGtm2osm/L0m4h/0HLOnNN4yFxdjU5K4nGnxXFmTLdgjlyFIig6wo0x3lqD7gm4/Eb08/2D\nYc91gc/ufnbX3XfPx8xN8vm89/157T31xWc/u599qyRJkkBERMIIudMFEBGRd7GxExEJho2diEgw\nbOxERIJhYyciEgwbOxGRYFxq7PX19TAajU7bzWYzMjMzodfrUVpa6vXiiIjIfaFyAz755BN8+eWX\nGDdunMP2gYEBFBQU4ODBgwgPD8fKlSvx1FNPIT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++SQOHz4Mg8HgsG/69On46KOPRn18RkYGzp8/73Db8Uhc\nmQ8YfPnY2tqKzMxM2bE0Mn9meyuz2TziPmarnD9y1ev10Ov1LtcUrLkKe40dAHJyclBbW+v0VcOu\nuHr1KiorK736ptsXX3yBRYsWOdy9S55htmJirt4hdGNPSUnBE088gY8//tjtx7a2tuK9995DfHy8\nV2qxWCyoqKjAhg0bvDLfLx2zFRNz9Q6hGzsw+H3xFRUVbp8BzJgxA0uWLPFaHUVFRVi5cuWwX2ZE\nnmG2YmKuygl7jX1IbGxsQHyV8O0LlJByzFZMzFU54c/YiYh+aRSveTokNzcXO3bs8HqBRETkHsVr\nngJASUlJ0K0wQkQkKtn
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x1023b3828>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# axes are in a two-dimensional array, indexed by [row, col]\n",
|
||
|
"for i in range(2):\n",
|
||
|
" for j in range(3):\n",
|
||
|
" ax[i, j].text(0.5, 0.5, str((i, j)),\n",
|
||
|
" fontsize=18, ha='center')\n",
|
||
|
"fig"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"In comparison to ``plt.subplot()``, ``plt.subplots()`` is more consistent with Python's conventional 0-based indexing."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## ``plt.GridSpec``: More Complicated Arrangements\n",
|
||
|
"\n",
|
||
|
"To go beyond a regular grid to subplots that span multiple rows and columns, ``plt.GridSpec()`` is the best tool.\n",
|
||
|
"The ``plt.GridSpec()`` object does not create a plot by itself; it is simply a convenient interface that is recognized by the ``plt.subplot()`` command.\n",
|
||
|
"For example, a gridspec for a grid of two rows and three columns with some specified width and height space looks like this:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"grid = plt.GridSpec(2, 3, wspace=0.4, hspace=0.3)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"From this we can specify subplot locations and extents using the familiary Python slicing syntax:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD/CAYAAADllv3BAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGBpJREFUeJzt3W9I1ef/x/HXWXa0dRoiM4JNzfWHoGBLB4OGJKwDwRzL\nzDolxxtFg90auDvrRupuiNZYN4Z5Yxs4ck2HzG0hrMY42o0aIZGVG7gR0oQRHFyplf93/W6E5zvn\n8qjn+hz1+j0fd6rz8Xx86/V5vzh+8jpvnzHGCADgjGeWugAAgF0EOwA4hmAHAMcQ7ADgGIIdABxD\nsAOAY+YV7Ddv3lQ4HJ71eCQS0YEDBxQKhdTa2mq9OCwN1htY2VLifcDnn3+u77//XmvXrp3x+OTk\npOrq6tTW1qbU1FQdPnxYb7zxhjIyMjwrFt5jvYGVL+4r9pycHJ09e3bW43fu3FFOTo4CgYBWr16t\n/Px8dXV1eVIkkof1Bla+uMEeDAa1atWqWY8/fPhQ69ati/177dq1Gh4etlsdko71Bla+uLdiniYQ\nCOjhw4exfz969EjPPffcrI8bHR1VT0+PMjMz/zMwkJipqSlFo1Ht2LFDaWlpnn0e1htIrkR6e97B\n/u+3lNm0aZPu3r2roaEhpaWlqaurS8eOHZ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h/TkvtmpU6f0888/q76+flG1XLx4UQ8ePNDx48f16aefqr29Xd99992CzpGenq7s7Gzl\n5uYqJSVFBQUFs14RzOc8vb296uzsVCQSUSQS0cDAgC5duvTUr+tp55/P99YmG2udDLaup2Swcc0u\ndZ0L6YulrNNG3yXDYnv
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10f438128>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.subplot(grid[0, 0])\n",
|
||
|
"plt.subplot(grid[0, 1:])\n",
|
||
|
"plt.subplot(grid[1, :2])\n",
|
||
|
"plt.subplot(grid[1, 2]);"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"This type of flexible grid alignment has a wide range of uses.\n",
|
||
|
"I most often use it when creating multi-axes histogram plots like the ones shown here:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAAFuCAYAAABOYJmxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsvVdwndd1vv+c3ht67wCJQjSKYhMt2VZsx7bs2NaFHdmZ\nZJKLtEkmfSbOJJnMOJkkk+R3kTJOn1jOON3j2I4TWxJlSpAoggABohG9l4PTez//C/6/bQAECBAE\nBULcz41lHOA7+3wg3r2+tdd6lyqfz+eRSCQSyYlCfdwLkEgkEsmDI8VbIpFITiBSvCUSieQEIsVb\nIpFITiBSvCUSieQEIsVbIpFITiDaw/7gX//1X/Pqq6+STqf50R/9UT7zmc8c5bqeeOT9lUgk9+NQ\n4v3OO+8wODjI1772NWKx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srIiGuCuXLkionOltlvJu28tFdyNrWWFyWQSr9d7T3rl\nYTbBo0CK9yPC5XJRWVl53MuQPOHsJsT7NbIoka5KpeLSpUv3bRrZKWDpdHrXa29dh9FoRK/XY7Va\nMRgMNDQ07FnfrdPp0Ol0pFIpTCYTIyMjqNVqLBYL7e3ttLS0iIPMvr4+QqEQDocDuLtJDAwMbEur\naLXaXTetnfdJqVG/deuWyI8rTT0KR2Ej+zAeKlK8JZL3KHsJ8X5t2rFYjMXFRYLBIHA3gn2Qg7qd\nOd2d0XlnZycqlYqGhgbUajVdXV3iGruVA3Z3d6PRaOjq6uKdd97B4XAwMDDAjRs3MBqNdHV1cf78\nec6fP088HsdgMGAymcR
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10ef598d0>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Create some normally distributed data\n",
|
||
|
"mean = [0, 0]\n",
|
||
|
"cov = [[1, 1], [1, 2]]\n",
|
||
|
"x, y = np.random.multivariate_normal(mean, cov, 3000).T\n",
|
||
|
"\n",
|
||
|
"# Set up the axes with gridspec\n",
|
||
|
"fig = plt.figure(figsize=(6, 6))\n",
|
||
|
"grid = plt.GridSpec(4, 4, hspace=0.2, wspace=0.2)\n",
|
||
|
"main_ax = fig.add_subplot(grid[:-1, 1:])\n",
|
||
|
"y_hist = fig.add_subplot(grid[:-1, 0], xticklabels=[], sharey=main_ax)\n",
|
||
|
"x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)\n",
|
||
|
"\n",
|
||
|
"# scatter points on the main axes\n",
|
||
|
"main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)\n",
|
||
|
"\n",
|
||
|
"# histogram on the attached axes\n",
|
||
|
"x_hist.hist(x, 40, histtype='stepfilled',\n",
|
||
|
" orientation='vertical', color='gray')\n",
|
||
|
"x_hist.invert_yaxis()\n",
|
||
|
"\n",
|
||
|
"y_hist.hist(y, 40, histtype='stepfilled',\n",
|
||
|
" orientation='horizontal', color='gray')\n",
|
||
|
"y_hist.invert_xaxis()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"This type of distribution plotted alongside its margins is common enough that it has its own plotting API in the Seaborn package; see [Visualization With Seaborn](04.14-Visualization-With-Seaborn.ipynb) for more details."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"<!--NAVIGATION-->\n",
|
||
|
"< [Customizing Colorbars](04.07-Customizing-Colorbars.ipynb) | [Contents](Index.ipynb) | [Text and Annotation](04.09-Text-and-Annotation.ipynb) >"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"anaconda-cloud": {},
|
||
|
"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.4.3"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 0
|
||
|
}
|