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

Skip to content

Commit 6e62218

Browse files
committed
Avoid using gca() in examples.
... in favor of more idiomatic approaches. (Except for examples specifically about the stateful API.)
1 parent 3a46327 commit 6e62218

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

examples/axes_grid1/simple_anchored_artists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def draw_sizebar(ax):
7373
ax.add_artist(asb)
7474

7575

76-
ax = plt.gca()
76+
fig, ax = plt.subplots()
7777
ax.set_aspect(1.)
7878

7979
draw_text(ax)

examples/scales/custom_scale.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class MercatorLatitudeScale(mscale.ScaleBase):
3838
"""
3939

4040
# The scale class must have a member ``name`` that defines the string used
41-
# to select the scale. For example, ``gca().set_yscale("mercator")`` would
42-
# be used to select this scale.
41+
# to select the scale. For example, ``ax.set_yscale("mercator")`` would be
42+
# used to select this scale.
4343
name = 'mercator'
4444

4545
def __init__(self, axis, *, thresh=np.deg2rad(85), **kwargs):
@@ -159,7 +159,7 @@ def inverted(self):
159159
s = np.radians(t)/2.
160160

161161
plt.plot(t, s, '-', lw=2)
162-
plt.gca().set_yscale('mercator')
162+
plt.yscale('mercator')
163163

164164
plt.xlabel('Longitude')
165165
plt.ylabel('Latitude')

examples/text_labels_and_annotations/text_alignment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
import matplotlib.pyplot as plt
1111

12+
fig, ax = plt.subplots()
13+
1214
# Build a rectangle in axes coords
1315
left, width = .25, .5
1416
bottom, height = .25, .5
1517
right = left + width
1618
top = bottom + height
17-
ax = plt.gca()
1819
p = plt.Rectangle((left, bottom), width, height, fill=False)
1920
p.set_transform(ax.transAxes)
2021
p.set_clip_on(False)
2122
ax.add_patch(p)
2223

23-
2424
ax.text(left, bottom, 'left top',
2525
horizontalalignment='left',
2626
verticalalignment='top',
@@ -75,6 +75,6 @@
7575
rotation=45,
7676
transform=ax.transAxes)
7777

78-
plt.axis('off')
78+
ax.set_axis_off()
7979

8080
plt.show()

examples/user_interfaces/embedding_in_wx5_sgskip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def demo():
5151
app = wit.InspectableApp()
5252
frame = wx.Frame(None, -1, 'Plotter')
5353
plotter = PlotNotebook(frame)
54-
axes1 = plotter.add('figure 1').gca()
54+
axes1 = plotter.add('figure 1').add_subplot()
5555
axes1.plot([1, 2, 3], [2, 1, 4])
56-
axes2 = plotter.add('figure 2').gca()
56+
axes2 = plotter.add('figure 2').add_subplot()
5757
axes2.plot([1, 2, 3, 4, 5], [2, 1, 4, 2, 3])
5858
frame.Show()
5959
app.MainLoop()

0 commit comments

Comments
 (0)