Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81436da

Browse files
authored
Merge pull request #20305 from anntzer/az
Merge two axisartist examples and point to standard methods.
2 parents c49d2bc + fbbcd39 commit 81436da

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed
Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,52 @@
11
"""
2-
==================
3-
Simple Axisartist1
4-
==================
2+
=============================
3+
Custom spines with axisartist
4+
=============================
55
6+
This example showcases the use of :mod:`.axisartist` to draw spines at custom
7+
positions (here, at ``y = 0``).
8+
9+
Note, however, that it is simpler to achieve this effect
10+
using standard `.Spine` methods, as demonstrated in
11+
:doc:`/gallery/ticks_and_spines/centered_spines_with_arrows`.
12+
13+
.. redirect-from:: /gallery/axisartist/simple_axisline2
614
"""
15+
716
import matplotlib.pyplot as plt
817
from mpl_toolkits import axisartist
18+
import numpy as np
19+
20+
21+
fig = plt.figure(figsize=(6, 3), constrained_layout=True)
22+
# To construct axes of two different classes, we need to use gridspec (or
23+
# MATLAB-style add_subplot calls).
24+
gs = fig.add_gridspec(1, 2)
25+
26+
27+
ax0 = fig.add_subplot(gs[0, 0], axes_class=axisartist.Axes)
28+
# Make a new axis along the first (x) axis which passes through y=0.
29+
ax0.axis["y=0"] = ax0.new_floating_axis(nth_coord=0, value=0,
30+
axis_direction="bottom")
31+
ax0.axis["y=0"].toggle(all=True)
32+
ax0.axis["y=0"].label.set_text("y = 0")
33+
# Make other axis invisible.
34+
ax0.axis["bottom", "top", "right"].set_visible(False)
935

10-
fig = plt.figure()
11-
fig.subplots_adjust(right=0.85)
12-
ax = fig.add_subplot(axes_class=axisartist.Axes)
1336

14-
# make some axis invisible
15-
ax.axis["bottom", "top", "right"].set_visible(False)
37+
# Alternatively, one can use AxesZero, which automatically sets up two
38+
# additional axis, named "xzero" (the y=0 axis) and "yzero" (the x=0 axis).
39+
ax1 = fig.add_subplot(gs[0, 1], axes_class=axisartist.axislines.AxesZero)
40+
# "xzero" and "yzero" default to invisible; make xzero axis visible.
41+
ax1.axis["xzero"].set_visible(True)
42+
ax1.axis["xzero"].label.set_text("Axis Zero")
43+
# Make other axis invisible.
44+
ax1.axis["bottom", "top", "right"].set_visible(False)
1645

17-
# make an new axis along the first axis axis (x-axis) which pass
18-
# through y=0.
19-
ax.axis["y=0"] = ax.new_floating_axis(nth_coord=0, value=0,
20-
axis_direction="bottom")
21-
ax.axis["y=0"].toggle(all=True)
22-
ax.axis["y=0"].label.set_text("y = 0")
2346

24-
ax.set_ylim(-2, 4)
47+
# Draw some sample data.
48+
x = np.arange(0, 2*np.pi, 0.01)
49+
ax0.plot(x, np.sin(x))
50+
ax1.plot(x, np.sin(x))
2551

2652
plt.show()

examples/axisartist/simple_axisline2.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)