@@ -999,6 +999,12 @@ def _add_colorbar(
999
999
ticklenratio = _not_none (ticklenratio , rc ['tick.lenratio' ])
1000
1000
tickwidthratio = _not_none (tickwidthratio , rc ['tick.widthratio' ])
1001
1001
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
1002
1008
1003
1009
# Build label and locator keyword argument dicts
1004
1010
# NOTE: This carefully handles the 'maxn' and 'maxn_minor' deprecations
@@ -1037,16 +1043,25 @@ def _add_colorbar(
1037
1043
# Generate and prepare the colorbar axes
1038
1044
# NOTE: The inset axes function needs 'label' to know how to pad the box
1039
1045
# 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' ])
1041
1054
length = _not_none (length , rc ['colorbar.length' ]) # for _add_guide_panel
1042
1055
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 )
1045
1058
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' ))
1050
1065
1051
1066
# Parse the colorbar mappable
1052
1067
# NOTE: Account for special case where auto colorbar is generated from 1D
0 commit comments