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

Skip to content

Commit 9c40739

Browse files
committed
Fix?
1 parent b132125 commit 9c40739

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ def _reposition_colorbar(cbax, renderer, *, offset=None):
576576
cbax.set_transform(fig.transSubfigure)
577577
cbax._set_position(pbcb)
578578
cbax.set_anchor(anchor)
579+
if location in ['bottom', 'top']:
580+
aspect = 1 / aspect
581+
print('CL', aspect, location)
579582
cbax.set_box_aspect(aspect)
580583
cbax.set_aspect('auto')
581584
return offset

lib/matplotlib/colorbar.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def draw(self, renderer):
231231

232232
class _ColorbarAxesLocator:
233233
"""
234-
Shrink the axes if there are vertical extends.
234+
Shrink the axes if there are extend triangles or rectangles.
235235
"""
236236
def __init__(self, cbar):
237237
self._cbar = cbar
@@ -267,7 +267,7 @@ def __call__(self, ax, renderer):
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.set_aspect((aspect / shrink))
271271
pos = pos.shrunk(shrink, 1).translated(offset * pos.width, 0)
272272
return pos
273273

@@ -621,7 +621,7 @@ def _do_extends(self, extendlen):
621621
# rectangle:
622622
xyout = np.array([[0, 0], [0, bot], [1, bot], [1, 0],
623623
[1, 1], [1, top], [0, top], [0, 1],
624-
[0, bot]])
624+
[0, 0]])
625625

626626
if self.orientation == 'horizontal':
627627
xyout = xyout[:, ::-1]
@@ -915,7 +915,7 @@ def set_alpha(self, alpha):
915915
"""Set the transparency between 0 (transparent) and 1 (opaque)."""
916916
self.alpha = alpha
917917

918-
def set_scale(self, scale, **kwargs):
918+
def set_scale(self, scale, **kwargs):
919919
"""
920920
Set the colorbar long axis scale.
921921
@@ -1090,7 +1090,6 @@ def _mesh(self):
10901090
(self.__scale == 'manual')):
10911091
# if a norm doesn't have a named scale, or we are not using a norm:
10921092
dv = self.vmax - self.vmin
1093-
# x = x * dv + self.vmin
10941093
y = y * dv + self.vmin
10951094
else:
10961095
y = norm.inverse(y)
@@ -1318,7 +1317,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13181317

13191318
anchor = kw.pop('anchor', loc_settings['anchor'])
13201319
panchor = kw.pop('panchor', loc_settings['panchor'])
1321-
1320+
aspect0 = aspect
13221321
# turn parents into a list if it is not already. We do this w/ np
13231322
# because `plt.subplots` can return an ndarray and is natural to
13241323
# pass to `colorbar`.
@@ -1376,7 +1375,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13761375
anchor=anchor,
13771376
panchor=panchor,
13781377
fraction=fraction,
1379-
aspect=aspect,
1378+
aspect=aspect0,
13801379
pad=pad)
13811380
# and we need to set the aspect ratio by hand...
13821381
cax.set_anchor(anchor)
@@ -1435,7 +1434,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14351434
panchor = kw.pop('panchor', loc_settings['panchor'])
14361435
pad = kw.pop('pad', loc_settings["pad"])
14371436
wh_space = 2 * pad / (1 - pad)
1438-
1437+
aspect0 = aspect
14391438
if location in ('left', 'right'):
14401439
# for shrinking
14411440
height_ratios = [
@@ -1492,7 +1491,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14921491
anchor=anchor,
14931492
panchor=panchor,
14941493
fraction=fraction,
1495-
aspect=aspect,
1494+
aspect=aspect0,
14961495
pad=pad)
14971496
return cax, kw
14981497

0 commit comments

Comments
 (0)