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

Skip to content

Commit fc695b2

Browse files
authored
Merge pull request #13279 from anntzer/docwarn
Remove a useless catch_warnings() from example.
2 parents 5d475d1 + abeede8 commit fc695b2

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

examples/subplots_axes_and_figures/demo_tight_layout.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def example_plot(ax):
100100

101101
fig = plt.figure()
102102

103-
import matplotlib.gridspec as gridspec
104-
105-
gs1 = gridspec.GridSpec(3, 1)
103+
gs1 = fig.add_gridspec(3, 1)
106104
ax1 = fig.add_subplot(gs1[0])
107105
ax2 = fig.add_subplot(gs1[1])
108106
ax3 = fig.add_subplot(gs1[2])
@@ -111,24 +109,19 @@ def example_plot(ax):
111109
example_plot(ax2)
112110
example_plot(ax3)
113111

114-
with warnings.catch_warnings():
115-
warnings.simplefilter("ignore", UserWarning)
116-
# This raises warnings since tight layout cannot
117-
# handle gridspec automatically. We are going to
118-
# do that manually so we can filter the warning.
119-
gs1.tight_layout(fig, rect=[None, None, 0.45, None])
112+
gs1.tight_layout(fig, rect=[None, None, 0.45, None])
120113

121-
gs2 = gridspec.GridSpec(2, 1)
114+
gs2 = fig.add_gridspec(2, 1)
122115
ax4 = fig.add_subplot(gs2[0])
123116
ax5 = fig.add_subplot(gs2[1])
124117

125118
example_plot(ax4)
126119
example_plot(ax5)
127120

128121
with warnings.catch_warnings():
129-
# This raises warnings since tight layout cannot
130-
# handle gridspec automatically. We are going to
131-
# do that manually so we can filter the warning.
122+
# gs2.tight_layout cannot handle the subplots from the first gridspec
123+
# (gs1), so it will raise a warning. We are going to match the gridspecs
124+
# manually so we can filter the warning away.
132125
warnings.simplefilter("ignore", UserWarning)
133126
gs2.tight_layout(fig, rect=[0.45, None, None, None])
134127

@@ -153,6 +146,6 @@ def example_plot(ax):
153146
import matplotlib
154147
matplotlib.pyplot.tight_layout
155148
matplotlib.figure.Figure.tight_layout
149+
matplotlib.figure.Figure.add_gridspec
156150
matplotlib.figure.Figure.add_subplot
157151
matplotlib.pyplot.subplot2grid
158-
matplotlib.gridspec.GridSpec

0 commit comments

Comments
 (0)