.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_recipes_centered_spines_with_arrows.py: =========================== Centered spines with arrows =========================== This example shows a way to draw a "math textbook" style plot, where the spines ("axes lines") are drawn at ``x = 0`` and ``y = 0``, and have arrows at their ends. .. image:: /gallery/recipes/images/sphx_glr_centered_spines_with_arrows_001.png :alt: centered spines with arrows :class: sphx-glr-single-img .. code-block:: default import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() # Move the left and bottom spines to x = 0 and y = 0, respectively. ax.spines["left"].set_position(("data", 0)) ax.spines["bottom"].set_position(("data", 0)) # Hide the top and right spines. ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) # Draw arrows (as black triangles: ">k"/"^k") at the end of the axes. In each # case, one of the coordinates (0) is a data coordinate (i.e., y = 0 or x = 0, # respectively) and the other one (1) is an axes coordinate (i.e., at the very # right/top of the axes). Also, disable clipping (clip_on=False) as the marker # actually spills out of the axes. ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False) ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False) # Some sample data. x = np.linspace(-0.5, 1., 100) ax.plot(x, np.sin(x*np.pi)) plt.show() .. _sphx_glr_download_gallery_recipes_centered_spines_with_arrows.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: centered_spines_with_arrows.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: centered_spines_with_arrows.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_