Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3752aec

Browse filesBrowse files
authored
Merge pull request #16109 from timhoffm/ax-naming
Name Axes variables ax instead of a
2 parents f653879 + 2aa91e4 commit 3752aec
Copy full SHA for 3752aec

File tree

Expand file treeCollapse file tree

12 files changed

+71
-74
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+71
-74
lines changed

‎examples/misc/hyperlinks_sgskip.py

Copy file name to clipboardExpand all lines: examples/misc/hyperlinks_sgskip.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
###############################################################################
1818

19-
f = plt.figure()
19+
fig = plt.figure()
2020
s = plt.scatter([1, 2, 3], [4, 5, 6])
2121
s.set_urls(['http://www.bbc.co.uk/news', 'http://www.google.com', None])
22-
f.savefig('scatter.svg')
22+
fig.savefig('scatter.svg')
2323

2424
###############################################################################
2525

26-
f = plt.figure()
26+
fig = plt.figure()
2727
delta = 0.025
2828
x = y = np.arange(-3.0, 3.0, delta)
2929
X, Y = np.meshgrid(x, y)
@@ -35,4 +35,4 @@
3535
origin='lower', extent=[-3, 3, -3, 3])
3636

3737
im.set_url('http://www.google.com')
38-
f.savefig('image.svg')
38+
fig.savefig('image.svg')

‎examples/shapes_and_collections/ellipse_demo.py

Copy file name to clipboardExpand all lines: examples/shapes_and_collections/ellipse_demo.py
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@
4242
import numpy as np
4343
from matplotlib.patches import Ellipse
4444

45-
delta = 45.0 # degrees
45+
angle_step = 45 # degrees
46+
angles = np.arange(0, 360, angle_step)
4647

47-
angles = np.arange(0, 360 + delta, delta)
48-
ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
48+
ax = plt.subplot(aspect='equal')
4949

50-
a = plt.subplot(111, aspect='equal')
50+
for angle in angles:
51+
ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)
52+
ax.add_artist(ellipse)
5153

52-
for e in ells:
53-
e.set_clip_box(a.bbox)
54-
e.set_alpha(0.1)
55-
a.add_artist(e)
56-
57-
plt.xlim(-2, 4)
58-
plt.ylim(-1, 3)
54+
plt.xlim(-2.2, 2.2)
55+
plt.ylim(-2.2, 2.2)
5956

6057
plt.show()
6158

‎examples/subplots_axes_and_figures/gridspec_nested.py

Copy file name to clipboardExpand all lines: examples/subplots_axes_and_figures/gridspec_nested.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ def format_axes(fig):
1818

1919

2020
# gridspec inside gridspec
21-
f = plt.figure()
21+
fig = plt.figure()
2222

23-
gs0 = gridspec.GridSpec(1, 2, figure=f)
23+
gs0 = gridspec.GridSpec(1, 2, figure=fig)
2424

2525
gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0])
2626

27-
ax1 = f.add_subplot(gs00[:-1, :])
28-
ax2 = f.add_subplot(gs00[-1, :-1])
29-
ax3 = f.add_subplot(gs00[-1, -1])
27+
ax1 = fig.add_subplot(gs00[:-1, :])
28+
ax2 = fig.add_subplot(gs00[-1, :-1])
29+
ax3 = fig.add_subplot(gs00[-1, -1])
3030

3131
# the following syntax does the same as the GridSpecFromSubplotSpec call above:
3232
gs01 = gs0[1].subgridspec(3, 3)
3333

34-
ax4 = f.add_subplot(gs01[:, :-1])
35-
ax5 = f.add_subplot(gs01[:-1, -1])
36-
ax6 = f.add_subplot(gs01[-1, -1])
34+
ax4 = fig.add_subplot(gs01[:, :-1])
35+
ax5 = fig.add_subplot(gs01[:-1, -1])
36+
ax6 = fig.add_subplot(gs01[-1, -1])
3737

3838
plt.suptitle("GridSpec Inside GridSpec")
39-
format_axes(f)
39+
format_axes(fig)
4040

4141
plt.show()

‎examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py

Copy file name to clipboardExpand all lines: examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
win.set_default_size(400, 300)
2323
win.set_title("Embedding in GTK")
2424

25-
f = Figure(figsize=(5, 4), dpi=100)
26-
a = f.add_subplot(1, 1, 1)
25+
fig = Figure(figsize=(5, 4), dpi=100)
26+
ax = fig.add_subplot(1, 1, 1)
2727
t = np.arange(0.0, 3.0, 0.01)
2828
s = np.sin(2*np.pi*t)
29-
a.plot(t, s)
29+
ax.plot(t, s)
3030

3131
vbox = Gtk.VBox()
3232
win.add(vbox)
3333

3434
# Add canvas to vbox
35-
canvas = FigureCanvas(f) # a Gtk.DrawingArea
35+
canvas = FigureCanvas(fig) # a Gtk.DrawingArea
3636
vbox.pack_start(canvas, True, True, 0)
3737

3838
# Create toolbar

‎examples/user_interfaces/embedding_in_gtk3_sgskip.py

Copy file name to clipboardExpand all lines: examples/user_interfaces/embedding_in_gtk3_sgskip.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
win.set_default_size(400, 300)
2222
win.set_title("Embedding in GTK")
2323

24-
f = Figure(figsize=(5, 4), dpi=100)
25-
a = f.add_subplot(111)
24+
fig = Figure(figsize=(5, 4), dpi=100)
25+
ax = fig.add_subplot(111)
2626
t = np.arange(0.0, 3.0, 0.01)
2727
s = np.sin(2*np.pi*t)
28-
a.plot(t, s)
28+
ax.plot(t, s)
2929

3030
sw = Gtk.ScrolledWindow()
3131
win.add(sw)
3232
# A scrolled window border goes outside the scrollbars and viewport
3333
sw.set_border_width(10)
3434

35-
canvas = FigureCanvas(f) # a Gtk.DrawingArea
35+
canvas = FigureCanvas(fig) # a Gtk.DrawingArea
3636
canvas.set_size_request(800, 600)
3737
sw.add_with_viewport(canvas)
3838

‎examples/user_interfaces/embedding_in_wx3_sgskip.py

Copy file name to clipboardExpand all lines: examples/user_interfaces/embedding_in_wx3_sgskip.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ def __init__(self, parent):
5757
self.Fit()
5858

5959
def init_plot_data(self):
60-
a = self.fig.add_subplot(111)
60+
ax = self.fig.add_subplot(111)
6161

6262
x = np.arange(120.0) * 2 * np.pi / 60.0
6363
y = np.arange(100.0) * 2 * np.pi / 50.0
6464
self.x, self.y = np.meshgrid(x, y)
6565
z = np.sin(self.x) + np.cos(self.y)
66-
self.im = a.imshow(z, cmap=cm.RdBu)
66+
self.im = ax.imshow(z, cmap=cm.RdBu)
6767

6868
zmax = np.max(z) - ERR_TOL
6969
ymax_i, xmax_i = np.nonzero(z >= zmax)
7070
if self.im.origin == 'upper':
7171
ymax_i = z.shape[0] - ymax_i
72-
self.lines = a.plot(xmax_i, ymax_i, 'ko')
72+
self.lines = ax.plot(xmax_i, ymax_i, 'ko')
7373

7474
self.toolbar.update() # Not sure why this is needed - ADS
7575

‎examples/user_interfaces/embedding_webagg_sgskip.py

Copy file name to clipboardExpand all lines: examples/user_interfaces/embedding_webagg_sgskip.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def create_figure():
3838
Creates a simple example figure.
3939
"""
4040
fig = Figure()
41-
a = fig.add_subplot(111)
41+
ax = fig.add_subplot(111)
4242
t = np.arange(0.0, 3.0, 0.01)
4343
s = np.sin(2 * np.pi * t)
44-
a.plot(t, s)
44+
ax.plot(t, s)
4545
return fig
4646

4747

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,8 +1358,8 @@ def add_subplot(self, *args, **kwargs):
13581358

13591359
if isinstance(args[0], SubplotBase):
13601360

1361-
a = args[0]
1362-
if a.get_figure() is not self:
1361+
ax = args[0]
1362+
if ax.get_figure() is not self:
13631363
raise ValueError(
13641364
"The Subplot must have been created in the present figure")
13651365
# make a key for the subplot (which includes the axes object id
@@ -1385,9 +1385,9 @@ def add_subplot(self, *args, **kwargs):
13851385
# more similar to add_axes.
13861386
self._axstack.remove(ax)
13871387

1388-
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
1388+
ax = subplot_class_factory(projection_class)(self, *args, **kwargs)
13891389

1390-
return self._add_axes_internal(key, a)
1390+
return self._add_axes_internal(key, ax)
13911391

13921392
def _add_axes_internal(self, key, ax):
13931393
"""Private helper for `add_axes` and `add_subplot`."""

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+20-20Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -961,18 +961,18 @@ def subplot(*args, **kwargs):
961961
"and/or 'nrows'. Did you intend to call subplots()?")
962962

963963
fig = gcf()
964-
a = fig.add_subplot(*args, **kwargs)
965-
bbox = a.bbox
966-
byebye = []
967-
for other in fig.axes:
968-
if other == a:
964+
ax = fig.add_subplot(*args, **kwargs)
965+
bbox = ax.bbox
966+
axes_to_delete = []
967+
for other_ax in fig.axes:
968+
if other_ax == ax:
969969
continue
970-
if bbox.fully_overlaps(other.bbox):
971-
byebye.append(other)
972-
for ax in byebye:
973-
delaxes(ax)
970+
if bbox.fully_overlaps(other_ax.bbox):
971+
axes_to_delete.append(other_ax)
972+
for ax_to_del in axes_to_delete:
973+
delaxes(ax_to_del)
974974

975-
return a
975+
return ax
976976

977977

978978
def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
@@ -1151,18 +1151,18 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, fig=None, **kwargs):
11511151
subplotspec = GridSpec(s1, s2).new_subplotspec(loc,
11521152
rowspan=rowspan,
11531153
colspan=colspan)
1154-
a = fig.add_subplot(subplotspec, **kwargs)
1155-
bbox = a.bbox
1156-
byebye = []
1157-
for other in fig.axes:
1158-
if other == a:
1154+
ax = fig.add_subplot(subplotspec, **kwargs)
1155+
bbox = ax.bbox
1156+
axes_to_delete = []
1157+
for other_ax in fig.axes:
1158+
if other_ax == ax:
11591159
continue
1160-
if bbox.fully_overlaps(other.bbox):
1161-
byebye.append(other)
1162-
for ax in byebye:
1163-
delaxes(ax)
1160+
if bbox.fully_overlaps(other_ax.bbox):
1161+
axes_to_delete.append(other_ax)
1162+
for ax_to_del in axes_to_delete:
1163+
delaxes(ax_to_del)
11641164

1165-
return a
1165+
return ax
11661166

11671167

11681168
def twinx(ax=None):

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def generate_EventCollection_plot():
3838
)
3939

4040
fig = plt.figure()
41-
splt = fig.add_subplot(1, 1, 1)
42-
splt.add_collection(coll)
43-
splt.set_title('EventCollection: default')
41+
ax = fig.add_subplot(1, 1, 1)
42+
ax.add_collection(coll)
43+
ax.set_title('EventCollection: default')
4444
props = {'positions': positions,
4545
'extra_positions': extra_positions,
4646
'orientation': orientation,
@@ -51,9 +51,9 @@ def generate_EventCollection_plot():
5151
'linestyle': linestyle,
5252
'antialiased': antialiased
5353
}
54-
splt.set_xlim(-1, 22)
55-
splt.set_ylim(0, 2)
56-
return splt, coll, props
54+
ax.set_xlim(-1, 22)
55+
ax.set_ylim(0, 2)
56+
return ax, coll, props
5757

5858

5959
@image_comparison(['EventCollection_plot__default'])

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ def test_image_shift():
518518

519519

520520
def test_image_edges():
521-
f = plt.figure(figsize=[1, 1])
522-
ax = f.add_axes([0, 0, 1, 1], frameon=False)
521+
fig = plt.figure(figsize=[1, 1])
522+
ax = fig.add_axes([0, 0, 1, 1], frameon=False)
523523

524524
data = np.tile(np.arange(12), 15).reshape(20, 9)
525525

@@ -534,7 +534,7 @@ def test_image_edges():
534534
ax.set_yticks([])
535535

536536
buf = io.BytesIO()
537-
f.savefig(buf, facecolor=(0, 1, 0))
537+
fig.savefig(buf, facecolor=(0, 1, 0))
538538

539539
buf.seek(0)
540540

‎tutorials/introductory/images.py

Copy file name to clipboardExpand all lines: tutorials/introductory/images.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@
214214
###############################################################################
215215
# You can also specify the clim using the returned object
216216
fig = plt.figure()
217-
a = fig.add_subplot(1, 2, 1)
217+
ax = fig.add_subplot(1, 2, 1)
218218
imgplot = plt.imshow(lum_img)
219-
a.set_title('Before')
219+
ax.set_title('Before')
220220
plt.colorbar(ticks=[0.1, 0.3, 0.5, 0.7], orientation='horizontal')
221-
a = fig.add_subplot(1, 2, 2)
221+
ax = fig.add_subplot(1, 2, 2)
222222
imgplot = plt.imshow(lum_img)
223223
imgplot.set_clim(0.0, 0.7)
224-
a.set_title('After')
224+
ax.set_title('After')
225225
plt.colorbar(ticks=[0.1, 0.3, 0.5, 0.7], orientation='horizontal')
226226

227227
###############################################################################

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.