{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Add lines directly to a figure\n\nYou can add artists such as a `.Line2D` directly to a figure. This is\ntypically useful for visual structuring.\n\n.. redirect-from:: /gallery/pyplots/fig_x\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nimport matplotlib.lines as lines\n\nfig, axs = plt.subplots(2, 2, gridspec_kw={'hspace': 0.4, 'wspace': 0.4})\nfig.add_artist(lines.Line2D([0, 1], [0.47, 0.47], linewidth=3))\nfig.add_artist(lines.Line2D([0.5, 0.5], [1, 0], linewidth=3))\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.pyplot.figure`\n - `matplotlib.lines`\n - `matplotlib.lines.Line2D`\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 }