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

Skip to content

Commit b59fbcc

Browse files
committed
Ensure extend[frac|size] warning triggers
1 parent c567af8 commit b59fbcc

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

‎proplot/axes/base.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,12 @@ def _add_colorbar(
999999
ticklenratio = _not_none(ticklenratio, rc['tick.lenratio'])
10001000
tickwidthratio = _not_none(tickwidthratio, rc['tick.widthratio'])
10011001
rasterized = _not_none(rasterized, rc['colorbar.rasterized'])
1002+
if extendsize is not None and extendfrac is not None:
1003+
warnings._warn_proplot(
1004+
f'You cannot specify both an absolute extendsize={extendsize!r} '
1005+
f"and a relative extendfrac={extendfrac!r}. Ignoring 'extendfrac'."
1006+
)
1007+
extendfrac = None
10021008

10031009
# Build label and locator keyword argument dicts
10041010
# NOTE: This carefully handles the 'maxn' and 'maxn_minor' deprecations
@@ -1037,16 +1043,25 @@ def _add_colorbar(
10371043
# Generate and prepare the colorbar axes
10381044
# NOTE: The inset axes function needs 'label' to know how to pad the box
10391045
# TODO: Use seperate keywords for frame properties vs. colorbar edge properties?
1040-
if loc in ('fill', 'left', 'right', 'top', 'bottom'):
1046+
# TODO: Have extendsize auto-adjust to the subplot size as it changes
1047+
fill = loc in ('fill', 'left', 'right', 'top', 'bottom')
1048+
if not fill:
1049+
extendsize = _not_none(extendsize, rc['colorbar.insetextend'])
1050+
kwargs.update({'label': label, 'length': length, 'width': width})
1051+
cax, kwargs = self._parse_colorbar_inset(loc=loc, pad=pad, **kwargs) # noqa: E501
1052+
else:
1053+
extendsize = _not_none(extendsize, rc['colorbar.extend'])
10411054
length = _not_none(length, rc['colorbar.length']) # for _add_guide_panel
10421055
kwargs.update({'align': align, 'length': length})
1043-
extendsize = _not_none(extendsize, rc['colorbar.extend'])
1044-
ax = self._add_guide_panel(loc, align, length=length, width=width, space=space, pad=pad) # noqa: E501
1056+
kw = {'width': width, 'space': space, 'pad': pad}
1057+
ax = self._add_guide_panel(loc, align, length, **kw)
10451058
cax, kwargs = ax._parse_colorbar_filled(**kwargs)
1046-
else:
1047-
kwargs.update({'label': label, 'length': length, 'width': width})
1048-
extendsize = _not_none(extendsize, rc['colorbar.insetextend'])
1049-
cax, kwargs = self._parse_colorbar_inset(loc=loc, pad=pad, **kwargs) # noqa: E501
1059+
vert = kwargs['orientation'] == 'vertical'
1060+
if extendfrac is None: # compute extendsize
1061+
width, height = cax._get_size_inches()
1062+
axsize = height if vert else width
1063+
extendsize = units(extendsize, 'em', 'in')
1064+
extendfrac = extendsize / max(axsize - 2 * extendsize, units(1, 'em', 'in'))
10501065

10511066
# Parse the colorbar mappable
10521067
# NOTE: Account for special case where auto colorbar is generated from 1D

0 commit comments

Comments
 (0)