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

Skip to content

Commit 60c0744

Browse files
committed
update tight_layout_guide
1 parent 29a2bc2 commit 60c0744

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

doc/users/tight_layout_guide.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,34 @@ Colorbar
284284

285285
If you create colorbar with :func:`~matplotlib.pyplot.colorbar`
286286
command, the created colorbar is an instance of Axes not Subplot, thus
287-
tight_layout does not work. One option is to use AxesGrid1 toolkit to explicitly create an axes for colorbar.
287+
tight_layout does not work. With Matplotlib v1.1, you may create a
288+
colobar as a subplot using the gridspec.
288289

289290
.. plot::
290291
:include-source:
291292
:context:
292293

293294
plt.close('all')
294295
fig = plt.figure(figsize=(4, 4))
296+
im = plt.imshow(arr, interpolation="none")
297+
298+
plt.colorbar(im, use_gridspec=True)
299+
300+
plt.tight_layout()
301+
302+
Another option is to use AxesGrid1 toolkit to
303+
explicitly create an axes for colorbar.
295304

296-
ax = plt.subplot(111)
305+
.. plot::
306+
:include-source:
307+
:context:
308+
309+
plt.close('all')
310+
fig = plt.figure(figsize=(4, 4))
297311
im = plt.imshow(arr, interpolation="none")
298312

299313
from mpl_toolkits.axes_grid1 import make_axes_locatable
300-
divider = make_axes_locatable(ax)
314+
divider = make_axes_locatable(plt.gca())
301315
cax = divider.append_axes("right", "5%", pad="3%")
302316
plt.colorbar(im, cax=cax)
303317

0 commit comments

Comments
 (0)