8000 Merge pull request #12001 from timhoffm/no-explicit-fignum-part2 · ColCarroll/matplotlib@b152acd · GitHub
[go: up one dir, main page]

Skip to content

Commit b152acd

Browse files
authored
Merge pull request matplotlib#12001 from timhoffm/no-explicit-fignum-part2
Do not use an explicit figum in plt.figure(1, ...) in simple cases
2 parents f6ea9a5 + e84b23b commit b152acd

27 files changed

+53
-54
lines changed

examples/axes_grid1/demo_axes_divider.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ def demo_simple_image(ax):
2626
plt.setp(cb.ax.get_yticklabels(), visible=False)
2727

2828

29-
def demo_locatable_axes_hard(fig1):
29+
def demo_locatable_axes_hard(fig):
3030

3131
from mpl_toolkits.axes_grid1 import SubplotDivider, Size
3232
from mpl_toolkits.axes_grid1.mpl_axes import Axes
3333

34-
divider = SubplotDivider(fig1, 2, 2, 2, aspect=True)
34+
divider = SubplotDivider(fig, 2, 2, 2, aspect=True)
3535

3636
# axes for image
37-
ax = Axes(fig1, divider.get_position())
37+
ax = Axes(fig, divider.get_position())
3838

3939
# axes for colorbar
40-
ax_cb = Axes(fig1, divider.get_position())
40+
ax_cb = Axes(fig, divider.get_position())
4141

4242
h = [Size.AxesX(ax), # main axes
4343
Size.Fixed(0.05), # padding, 0.1 inch
@@ -52,8 +52,8 @@ def demo_locatable_axes_hard(fig1):
5252
ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
5353
ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))
5454

55-
fig1.add_axes(ax)
56-
fig1.add_axes(ax_cb)
55+
fig.add_axes(ax)
56+
fig.add_axes(ax_cb)
5757

5858
ax_cb.axis["left"].toggle(all=False)
5959
ax_cb.axis["right"].toggle(ticks=True)
@@ -71,8 +71,8 @@ def demo_locatable_axes_easy(ax):
7171
divider = make_axes_locatable(ax)
7272

7373
ax_cb = divider.new_horizontal(size="5%", pad=0.05)
74-
fig1 = ax.get_figure()
75-
fig1.add_axes(ax_cb)
74+
fig = ax.get_figure()
75+
fig.add_axes(ax_cb)
7676

7777
Z, extent = get_demo_image()
7878
im = ax.imshow(Z, extent=extent, interpolation="nearest")
@@ -99,31 +99,30 @@ def demo_images_side_by_side(ax):
9999

100100
def demo():
101101

102-
fig1 = plt.figure(1, (6, 6))
103-
fig1.clf()
102+
fig = plt.figure(figsize=(6, 6))
104103

105104
# PLOT 1
106105
# simple image & colorbar
107-
ax = fig1.add_subplot(2, 2, 1)
106+
ax = fig.add_subplot(2, 2, 1)
108107
demo_simple_image(ax)
109108

110109
# PLOT 2
111110
# image and colorbar whose location is adjusted in the drawing time.
112111
# a hard way
113112

114-
demo_locatable_axes_hard(fig1)
113+
demo_locatable_axes_hard(fig)
115114

116115
# PLOT 3
117116
# image and colorbar whose location is adjusted in the drawing time.
118117
# a easy way
119118

120-
ax = fig1.add_subplot(2, 2, 3)
119+
ax = fig.add_subplot(2, 2, 3)
121120
demo_locatable_axes_easy(ax)
122121

123122
# PLOT 4
124123
# two images side by side with fixed padding.
125124

126-
ax = fig1.add_subplot(2, 2, 4)
125+
ax = fig.add_subplot(2, 2, 4)
127126
demo_images_side_by_side(ax)
128127

129128
plt.show()

examples/axes_grid1/demo_fixed_size_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111

1212

1313
def demo_fixed_size_axes():
14-
fig1 = plt.figure(1, (6, 6))
14+
fig = plt.figure(figsize=(6, 6))
1515

1616
# The first items are for padding and the second items are for the axes.
1717
# sizes are in inch.
1818
h = [Size.Fixed(1.0), Size.Fixed(4.5)]
1919
v = [Size.Fixed(0.7), Size.Fixed(5.)]
2020

21-
divider = Divider(fig1, (0.0, 0.0, 1., 1.), h, v, aspect=False)
21+
divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)
2222
# the width and height of the rectangle is ignored.
2323

24-
ax = Axes(fig1, divider.get_position())
24+
ax = Axes(fig, divider.get_position())
2525
ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
2626

27-
fig1.add_axes(ax)
27+
fig.add_axes(ax)
2828

2929
ax.plot([1, 2, 3])
3030

3131

3232
def demo_fixed_pad_axes():
33-
fig = plt.figure(2, (6, 6))
33+
fig = plt.figure(figsize=(6, 6))
3434

3535
# The first & third items are for padding and the second items are for the
3636
# axes. Sizes are in inches.

examples/axes_grid1/simple_axes_divider2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
from mpl_toolkits.axes_grid1 import Divider
99
import matplotlib.pyplot as plt
1010

11-
fig1 = plt.figure(1, (5.5, 4.))
11+
fig = plt.figure(figsize=(5.5, 4.))
1212

1313
# the rect parameter will be ignore as we will set axes_locator
1414
rect = (0.1, 0.1, 0.8, 0.8)
15-
ax = [fig1.add_axes(rect, label="%d" % i) for i in range(4)]
15+
ax = [fig.add_axes(rect, label="%d" % i) for i in range(4)]
1616

1717
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.),
1818
Size.Scaled(.5)]
1919

2020
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
2121

2222
# divide the axes rectangle into grid whose size is specified by horiz * vert
23-
divider = Divider(fig1, rect, horiz, vert, aspect=False)
23+
divider = Divider(fig, rect, horiz, vert, aspect=False)
2424

2525
ax[0].set_axes_locator(divider.new_locator(nx=0, ny=0))
2626
ax[1].set_axes_locator(divider.new_locator(nx=0, ny=2))

examples/axes_grid1/simple_axes_divider3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import matplotlib.pyplot as plt
1010

1111

12-
fig1 = plt.figure(1, (5.5, 4))
12+
fig = plt.figure(figsize=(5.5, 4))
1313

1414
# the rect parameter will be ignore as we will set axes_locator
1515
rect = (0.1, 0.1, 0.8, 0.8)
16-
ax = [fig1.add_axes(rect, label="%d" % i) for i in range(4)]
16+
ax = [fig.add_axes(rect, label="%d" % i) for i in range(4)]
1717

1818

1919
horiz = [Size.AxesX(ax[0]), Size.Fixed(.5), Size.AxesX(ax[1])]
2020
vert = [Size.AxesY(ax[0]), Size.Fixed(.5), Size.AxesY(ax[2])]
2121

2222
# divide the axes rectangle into grid whose size is specified by horiz * vert
23-
divider = Divider(fig1, rect, horiz, vert, aspect=False)
23+
divider = Divider(fig, rect, horiz, vert, aspect=False)
2424

2525

2626
ax[0].set_axes_locator(divider.new_locator(nx=0, ny=0))

examples/axisartist/demo_axis_direction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def add_floating_axis2(ax1):
7373
return axis
7474

7575

76-
fig = plt.figure(1, figsize=(8, 4))
76+
fig = plt.figure(figsize=(8, 4))
7777
fig.clf()
7878
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99,
7979
wspace=0.01, hspace=0.01)

examples/axisartist/demo_curvelinear_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def curvelinear_test2(fig):
131131
ax1.grid(True, zorder=0)
132132

133133
if 1:
134-
fig = plt.figure(1, figsize=(7, 4))
134+
fig = plt.figure(figsize=(7, 4))
135135
fig.clf()
136136

137137
curvelinear_test1(fig)

examples/axisartist/demo_curvelinear_grid2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def inv_tr(x, y):
6565

6666

6767
if 1:
68-
fig = plt.figure(1, figsize=(7, 4))
68+
fig = plt.figure(figsize=(7, 4))
6969
fig.clf()
7070

7171
curvelinear_test1(fig)

examples/axisartist/demo_floating_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def setup_axes3(fig, rect):
143143

144144

145145
##########################################################
146-
fig = plt.figure(1, figsize=(8, 4))
146+
fig = plt.figure(figsize=(8, 4))
147147
fig.subplots_adjust(wspace=0.3, left=0.05, right=0.95)
148148

149149
ax1, aux_ax1 = setup_axes1(fig, 131)

examples/axisartist/demo_floating_axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def curvelinear_test2(fig):
6464

6565
ax1.grid(True)
6666

67-
fig = plt.figure(1, figsize=(5, 5))
67+
fig = plt.figure(figsize=(5, 5))
6868
fig.clf()
6969

7070
curvelinear_test2(fig)

examples/axisartist/demo_ticklabel_alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def setup_axes(fig, rect):
2222
return ax
2323

2424

25-
fig = plt.figure(1, figsize=(3, 5))
25+
fig = plt.figure(figsize=(3, 5))
2626
fig.subplots_adjust(left=0.5, hspace=0.7)
2727

2828
ax = setup_axes(fig, 311)

0 commit comments

Comments
 (0)
0