@@ -100,9 +100,7 @@ def example_plot(ax):
100
100
101
101
fig = plt .figure ()
102
102
103
- import matplotlib .gridspec as gridspec
104
-
105
- gs1 = gridspec .GridSpec (3 , 1 )
103
+ gs1 = fig .add_gridspec (3 , 1 )
106
104
ax1 = fig .add_subplot (gs1 [0 ])
107
105
ax2 = fig .add_subplot (gs1 [1 ])
108
106
ax3 = fig .add_subplot (gs1 [2 ])
@@ -111,24 +109,19 @@ def example_plot(ax):
111
109
example_plot (ax2 )
112
110
example_plot (ax3 )
113
111
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 ])
120
113
121
- gs2 = gridspec . GridSpec (2 , 1 )
114
+ gs2 = fig . add_gridspec (2 , 1 )
122
115
ax4 = fig .add_subplot (gs2 [0 ])
123
116
ax5 = fig .add_subplot (gs2 [1 ])
124
117
125
118
example_plot (ax4 )
126
119
example_plot (ax5 )
127
120
128
121
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 .
132
125
warnings .simplefilter ("ignore" , UserWarning )
133
126
gs2 .tight_layout (fig , rect = [0.45 , None , None , None ])
134
127
@@ -153,6 +146,6 @@ def example_plot(ax):
153
146
import matplotlib
154
147
matplotlib .pyplot .tight_layout
155
148
matplotlib .figure .Figure .tight_layout
149
+ matplotlib .figure .Figure .add_gridspec
156
150
matplotlib .figure .Figure .add_subplot
157
151
matplotlib .pyplot .subplot2grid
158
- matplotlib .gridspec .GridSpec
0 commit comments