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

Skip to content

Commit 1af2d06

Browse files
authored
Merge pull request #16313 from anntzer/clg
Cleanup constrainedlayout_guide.
2 parents 39301db + 0bf554b commit 1af2d06

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
normalized figure coordinates. It can happen that your axis labels or
4545
titles (or sometimes even ticklabels) go outside the figure area, and are thus
4646
clipped.
47-
4847
"""
4948

5049
# sphinx_gallery_thumbnail_number = 18
@@ -58,19 +57,20 @@
5857

5958
plt.rcParams['savefig.facecolor'] = "0.8"
6059
plt.rcParams['figure.figsize'] = 4.5, 4.
60+
plt.rcParams['figure.max_open_warning'] = 50
6161

6262

63-
def example_plot(ax, fontsize=12, nodec=False):
63+
def example_plot(ax, fontsize=12, hide_labels=False):
6464
ax.plot([1, 2])
6565

6666
ax.locator_params(nbins=3)
67-
if not nodec:
67+
if hide_labels:
68+
ax.set_xticklabels([])
69+
ax.set_yticklabels([])
70+
else:
6871
ax.set_xlabel('x-label', fontsize=fontsize)
6972
ax.set_ylabel('y-label', fontsize=fontsize)
7073
ax.set_title('Title', fontsize=fontsize)
71-
else:
72-
ax.set_xticklabels('')
73-
ax.set_yticklabels('')
7474

7575

7676
fig, ax = plt.subplots(constrained_layout=False)
@@ -266,17 +266,13 @@ def example_plot(ax, fontsize=12, nodec=False):
266266

267267
fig, axs = plt.subplots(2, 2, constrained_layout=True)
268268
for ax in axs.flat:
269-
example_plot(ax, nodec=True)
270-
ax.set_xticklabels('')
271-
ax.set_yticklabels('')
269+
example_plot(ax, hide_labels=True)
272270
fig.set_constrained_layout_pads(w_pad=4./72., h_pad=4./72.,
273271
hspace=0., wspace=0.)
274272

275273
fig, axs = plt.subplots(2, 2, constrained_layout=True)
276274
for ax in axs.flat:
277-
example_plot(ax, nodec=True)
278-
ax.set_xticklabels('')
279-
ax.set_yticklabels('')
275+
example_plot(ax, hide_labels=True)
280276
fig.set_constrained_layout_pads(w_pad=2./72., h_pad=2./72.,
281277
hspace=0., wspace=0.)
282278

@@ -289,9 +285,7 @@ def example_plot(ax, fontsize=12, nodec=False):
289285

290286
fig, axs = plt.subplots(2, 2, constrained_layout=True)
291287
for ax in axs.flat:
292-
example_plot(ax, nodec=True)
293-
ax.set_xticklabels('')
294-
ax.set_yticklabels('')
288+
example_plot(ax, hide_labels=True)
295289
fig.set_constrained_layout_pads(w_pad=2./72., h_pad=2./72.,
296290
hspace=0.2, wspace=0.2)
297291

0 commit comments

Comments
 (0)