{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Share axis limits and views\n\nIt's common to make two or more plots which share an axis, e.g., two subplots\nwith time as a common axis. When you pan and zoom around on one, you want the\nother to move around with you. To facilitate this, matplotlib Axes support a\n``sharex`` and ``sharey`` attribute. When you create a `~.pyplot.subplot` or\n`~.pyplot.axes`, you can pass in a keyword indicating what Axes you want to\nshare with.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nt = np.arange(0, 10, 0.01)\n\nax1 = plt.subplot(211)\nax1.plot(t, np.sin(2*np.pi*t))\n\nax2 = plt.subplot(212, sharex=ax1)\nax2.plot(t, np.sin(4*np.pi*t))\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tags::\n\n component: axis\n plot-type: line\n level: beginner\n\n" ] } ], "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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }