Skip to content

Commit f369b10

Browse files
Doc: spines arrows example (#17180)
1 parent d4bd4e7 commit f369b10

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

examples/axisartist/demo_axisline_style.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
================
55
66
This example shows some configurations for axis style.
7+
8+
Note: The `mpl_toolkits.axisartist` axes classes may be confusing for new
9+
users. If the only aim is to obtain arrow heads at the ends of the axes,
10+
rather check out the :doc:`/gallery/recipes/centered_spines_with_arrows`
11+
example.
712
"""
813

914
from mpl_toolkits.axisartist.axislines import SubplotZero
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
===========================
3+
Centered spines with arrows
4+
===========================
5+
6+
This example shows a way to draw a "math textbook" style plot, where the
7+
spines ("axes lines") are drawn at ``x = 0`` and ``y = 0``, and have arrows at
8+
their ends.
9+
"""
10+
11+
import matplotlib.pyplot as plt
12+
import numpy as np
13+
14+
15+
fig, ax = plt.subplots()
16+
# Move the left and bottom spines to x = 0 and y = 0, respectively.
17+
ax.spines["left"].set_position(("data", 0))
18+
ax.spines["bottom"].set_position(("data", 0))
19+
# Hide the top and right spines.
20+
ax.spines["top"].set_visible(False)
21+
ax.spines["right"].set_visible(False)
22+
23+
# Draw arrows (as black triangles: ">k"/"^k") at the end of the axes. In each
24+
# case, one of the coordinates (0) is a data coordinate (i.e., y = 0 or x = 0,
25+
# respectively) and the other one (1) is an axes coordinate (i.e., at the very
26+
# right/top of the axes). Also, disable clipping (clip_on=False) as the marker
27+
# actually spills out of the axes.
28+
ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False)
29+
ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False)
30+
31+
# Some sample data.
32+
x = np.linspace(-0.5, 1., 100)
33+
ax.plot(x, np.sin(x*np.pi))
34+
35+
plt.show()

examples/ticks_and_spines/spine_placement_demo.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
====================
55
66
Adjusting the location and appearance of axis spines.
7+
8+
Note: If you want to obtain arrow heads at the ends of the axes, also check
9+
out the :doc:`/gallery/recipes/centered_spines_with_arrows` example.
710
"""
811
import numpy as np
912
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)