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

Skip to content

Commit e391e62

Browse files
committed
FIX
1 parent 52060df commit e391e62

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
New colorbar methods
22
--------------------
33

4-
Colorbar now has `~.colorbar.set_scale`, `~.colorbar.get_scale` to set and get
5-
the scale from the main colorbar axis and `~.colorbar.set_aspect` to set the
4+
Colorbar now has `~.Colorbar.set_scale`, `~.Colorbar.get_scale` to set and get
5+
the scale from the main colorbar axis and `~.Colorbar.set_aspect` to set the
66
aspect ratio of the colorbar axes.

lib/matplotlib/colorbar.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ def __call__(self, ax, renderer):
263263
# extend tri/rectangles.
264264
if self._cbar.orientation == 'vertical':
265265
if aspect:
266-
self._cbar.set_aspect(aspect*shrink)
266+
self._cbar.ax.set_box_aspect(aspect*shrink)
267267
pos = pos.shrunk(1, shrink).translated(0, offset * pos.height)
268268
else:
269269
if aspect:
270-
self._cbar.set_aspect(1 / (aspect / shrink))
270+
self._cbar.ax.set_box_aspect(1/(aspect * shrink))
271271
pos = pos.shrunk(shrink, 1).translated(offset * pos.width, 0)
272272
return pos
273273

@@ -963,6 +963,7 @@ def set_aspect(self, aspect):
963963
"""
964964
Set ratio of the long axis to short axis.
965965
"""
966+
self.ax._colorbar_info['aspect'] = aspect
966967
if self.orientation == 'horizontal':
967968
aspect = 1 / aspect
968969
self.ax.set_box_aspect(aspect)
@@ -1318,7 +1319,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13181319

13191320
anchor = kw.pop('anchor', loc_settings['anchor'])
13201321
panchor = kw.pop('panchor', loc_settings['panchor'])
1321-
1322+
aspect0 = aspect
13221323
# turn parents into a list if it is not already. We do this w/ np
13231324
# because `plt.subplots` can return an ndarray and is natural to
13241325
# pass to `colorbar`.
@@ -1376,7 +1377,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13761377
anchor=anchor,
13771378
panchor=panchor,
13781379
fraction=fraction,
1379-
aspect=aspect,
1380+
aspect=aspect0,
13801381
pad=pad)
13811382
# and we need to set the aspect ratio by hand...
13821383
cax.set_anchor(anchor)
@@ -1431,6 +1432,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14311432
kw['orientation'] = loc_settings['orientation']
14321433
location = kw['ticklocation'] = loc_settings['location']
14331434

1435+
aspect0 = aspect
14341436
anchor = kw.pop('anchor', loc_settings['anchor'])
14351437
panchor = kw.pop('panchor', loc_settings['panchor'])
14361438
pad = kw.pop('pad', loc_settings["pad"])
@@ -1492,7 +1494,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14921494
anchor=anchor,
14931495
panchor=panchor,
14941496
fraction=fraction,
1495-
aspect=aspect,
1497+
aspect=aspect0,
14961498
pad=pad)
14971499
return cax, kw
14981500

0 commit comments

Comments
 (0)