Skip to content

Commit d42384d

Browse files
authored
Merge pull request #29625 from meeseeksmachine/auto-backport-of-pr-29622-on-v3.10.x
2 parents 9f74bf3 + 1af4b2e commit d42384d

File tree

1 file changed

+17
-13
lines changed
  • galleries/examples/lines_bars_and_markers

1 file changed

+17
-13
lines changed

galleries/examples/pyplots/axline.py renamed to galleries/examples/lines_bars_and_markers/axline.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
sigmoid function.
1010
1111
`~.axes.Axes.axline` draws infinite straight lines in arbitrary directions.
12+
13+
.. redirect-from:: /gallery/pyplot/axline
1214
"""
1315

1416
import matplotlib.pyplot as plt
@@ -17,28 +19,28 @@
1719
t = np.linspace(-10, 10, 100)
1820
sig = 1 / (1 + np.exp(-t))
1921

20-
plt.axhline(y=0, color="black", linestyle="--")
21-
plt.axhline(y=0.5, color="black", linestyle=":")
22-
plt.axhline(y=1.0, color="black", linestyle="--")
23-
plt.axvline(color="grey")
24-
plt.axline((0, 0.5), slope=0.25, color="black", linestyle=(0, (5, 5)))
25-
plt.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$")
26-
plt.xlim(-10, 10)
27-
plt.xlabel("t")
28-
plt.legend(fontsize=14)
22+
fig, ax = plt.subplots()
23+
ax.axhline(y=0, color="black", linestyle="--")
24+
ax.axhline(y=0.5, color="black", linestyle=":")
25+
ax.axhline(y=1.0, color="black", linestyle="--")
26+
ax.axvline(color="grey")
27+
ax.axline((0, 0.5), slope=0.25, color="black", linestyle=(0, (5, 5)))
28+
ax.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$")
29+
ax.set(xlim=(-10, 10), xlabel="t")
30+
ax.legend(fontsize=14)
2931
plt.show()
3032

3133
# %%
32-
# `~.axes.Axes.axline` can also be used with a ``transform`` parameter, which
34+
# `~.axes.Axes.axline` can also be used with a *transform* parameter, which
3335
# applies to the point, but not to the slope. This can be useful for drawing
3436
# diagonal grid lines with a fixed slope, which stay in place when the
3537
# plot limits are moved.
3638

39+
fig, ax = plt.subplots()
3740
for pos in np.linspace(-2, 1, 10):
38-
plt.axline((pos, 0), slope=0.5, color='k', transform=plt.gca().transAxes)
41+
ax.axline((pos, 0), slope=0.5, color='k', transform=ax.transAxes)
3942

40-
plt.ylim([0, 1])
41-
plt.xlim([0, 1])
43+
ax.set(xlim=(0, 1), ylim=(0, 1))
4244
plt.show()
4345

4446
# %%
@@ -57,3 +59,5 @@
5759
#
5860
# `~.Axes.axhspan`, `~.Axes.axvspan` draw rectangles that span the Axes in one
5961
# direction and are bounded in the other direction.
62+
#
63+
# .. tags:: component: annotation

0 commit comments

Comments
 (0)