8000 FIX: address review comments · matplotlib/matplotlib@ab13883 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab13883

Browse files
committed
FIX: address review comments
1 parent ffb90ff commit ab13883

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

lib/matplotlib/colorbar.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def __call__(self, ax, renderer):
269269
offset = extendlen[0] / len
270270
# we need to reset the aspect ratio of the axes to account
271271
# of the extends...
272-
if not self._cbar._userax:
272+
if hasattr< 10000 /span>(ax, '_colorbar_info'):
273273
aspect = ax._colorbar_info['aspect']
274274
else:
275275
aspect = False
@@ -278,15 +278,13 @@ def __call__(self, ax, renderer):
278278
if self._cbar.orientation == 'vertical':
279279
if aspect:
280280
ax.set_aspect(aspect*shrink)
281-
offset = offset * pos.height
282-
pos = pos.shrunk(1, shrink).translated(0, offset)
281+
pos = pos.shrunk(1, shrink).translated(0, offset * pos.height)
283282
else:
284283
if aspect:
285284
ax.set_aspect(aspect/shrink)
286-
offset = offset * pos.width
287-
pos = pos.shrunk(shrink, 1).translated(offset, 0)
285+
pos = pos.shrunk(shrink, 1).translated(offset * pos.width, 0)
288286
return pos
289-
287+
290288
def get_subplotspec(self):
291289
# make tight_layout happy..
292290
return self._cbar.ax.get_subplotspec()
@@ -368,9 +366,6 @@ class Colorbar:
368366
extendrec
369367
370368
label : str
371-
372-
userax : boolean
373-
Whether the user created the axes or not. Default True
374369
"""
375370

376371
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
@@ -391,7 +386,6 @@ def __init__(self, ax, mappable=None, *, cmap=None,
391386
extendfrac=None,
392387
extendrect=False,
393388
label='',
394-
userax=True,
395389
):
396390

397391
if mappable is None:
@@ -431,7 +425,6 @@ def __init__(self, ax, mappable=None, *, cmap=None,
431425
['uniform', 'proportional'], spacing=spacing)
432426

433427
self.ax = ax
434-
self._userax = userax
435428
self.ax._axes_locator = _ColorbarAxesLocator(self)
436429
ax.set(navigate=False)
437430

@@ -621,20 +614,21 @@ def _do_extends(self, extendlen):
621614
"""
622615
# extend lengths are fraction of the *inner* part of colorbar,
623616
# not the total colorbar:
624-
elower = extendlen[0] if self._extend_lower() else 0
625-
eupper = extendlen[1] if self._extend_upper() else 0
626-
top = eupper + 1
617+
bot = extendlen[0] if self._extend_lower() else 0
618+
bot = -bot
619+
top = extendlen[1] if self._extend_upper() else 0
620+
top = top + 1
627621

628622
# xyout is the outline of the colorbar including the extend patches:
629623
if not self.extendrect:
630624
# triangle:
631-
xyout = np.array([[0, 0], [0.5, -elower], [1, 0],
625+
xyout = np.array([[0, 0], [0.5, bot], [1, 0],
632626
[1, 1], [0.5, top], [0, 1], [0, 0]])
633627
else:
634628
# rectangle:
635-
xyout = np.array([[0, 0], [0, -elower], [1, -elower], [1, 0],
629+
xyout = np.array([[0, 0], [0, bot], [1, bot], [1, 0],
636630
[1, 1], [1, top], [0, top], [0, 1],
637-
[0, -elower]])
631+
[0, bot]])
638632

639633
if self.orientation == 'horizontal':
640634
xyout = xyout[:, ::-1]
@@ -656,10 +650,10 @@ def _do_extends(self, extendlen):
656650
if self._extend_lower():
657651
if not self.extendrect:
658652
# triangle
659-
xy = np.array([[0.5, -elower], [1, 0], [0, 0]])
653+
xy = np.array([[0.5, bot], [1, 0], [0, 0]])
660654
else:
661655
# rectangle
662-
xy = np.array([[0, -elower], [1., -elower], [1, 0], [0, 0]])
656+
xy = np.array([[0, bot], [1., bot], [1, 0], [0, 0]])
663657
if self.orientation == 'horizontal':
664658
xy = xy[:, ::-1]
665659
# add the patch

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,14 +1142,14 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
11421142
# Store the value of gca so that we can set it back later on.
11431143
if cax is None:
11441144
current_ax = self.gca()
1145-
kw['userax'] = False
1145+
userax = False
11461146
if (use_gridspec and isinstance(ax, SubplotBase)
11471147
and not self.get_constrained_layout()):
11481148
cax, kw = cbar.make_axes_gridspec(ax, **kw)
11491149
else:
11501150
cax, kw = cbar.make_axes(ax, **kw)
11511151
else:
1152-
kw['userax'] = True
1152+
userax = True
11531153

11541154
# need to remove kws that cannot be passed to Colorbar
11551155
NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
@@ -1158,7 +1158,7 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
11581158

11591159
cb = cbar.Colorbar(cax, mappable, **cb_kw)
11601160

1161-
if not kw['userax']:
1161+
if not userax:
11621162
self.sca(current_ax)
11631163
self.stale = True
11641164
return cb

lib/matplotlib/tests/test_colorbar.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def _colorbar_extension_shape(spacing):
5656
cax = fig.add_subplot(4, 1, i + 1)
5757
# Generate the colorbar.
5858
Colorbar(cax, cmap=cmap, norm=norm,
59-
boundaries=boundaries, values=values,
60-
extend=extension_type, extendrect=True,
61-
orientation='horizontal', spacing=spacing)
59+
boundaries=boundaries, values=values,
60+
extend=extension_type, extendrect=True,
61+
orientation='horizontal', spacing=spacing)
6262
# Turn off text and ticks.
6363
cax.tick_params(left=False, labelleft=False,
6464
bottom=False, labelbottom=False)
@@ -761,6 +761,7 @@ def test_inset_colorbar_layout():
761761
# it was being dropped from the list of children...
762762
np.testing.assert_allclose(cb.ax.get_position().bounds,
763763
[0.87, 0.342, 0.0237, 0.315], atol=0.01)
764+
assert cb.ax in ax.child_axes
764765

765766

766767
@image_comparison(['colorbar_twoslope.png'], remove_text=True,

0 commit comments

Comments
 (0)
0