Skip to content

Commit b42bda8

Browse files
committed
Infer colorbar loc from orientation (fix #314)
1 parent 760979f commit b42bda8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

proplot/axes/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,18 +1745,18 @@ def _parse_colorbar_filled(
17451745
ax.patch.set_facecolor('none') # ignore axes.alpha application
17461746

17471747
# Handle default keyword args
1748-
if side in ('bottom', 'top'):
1748+
if orientation is None:
1749+
orientation = 'horizontal' if side in ('bottom', 'top') else 'vertical'
1750+
if orientation == 'horizontal':
17491751
outside, inside = 'bottom', 'top'
17501752
if side == 'top':
17511753
outside, inside = inside, outside
17521754
ticklocation = _not_none(ticklocation, outside)
1753-
orientation = _not_none(orientation, 'horizontal')
17541755
else:
17551756
outside, inside = 'left', 'right'
17561757
if side == 'right':
17571758
outside, inside = inside, outside
17581759
ticklocation = _not_none(ticklocation, outside)
1759-
orientation = _not_none(orientation, 'vertical')
17601760
kwargs.update({'orientation': orientation, 'ticklocation': ticklocation})
17611761
return ax, kwargs
17621762

@@ -1819,8 +1819,8 @@ def _parse_colorbar_inset(
18191819
# Handle default keyword args
18201820
if orientation is not None and orientation != 'horizontal':
18211821
warnings._warn_proplot(
1822-
f'Orientation for inset colorbars must be horizontal, '
1823-
f'ignoring orientation={orientation!r}.'
1822+
f'Orientation for inset colorbars must be horizontal. '
1823+
f'Ignoring orientation={orientation!r}.'
18241824
)
18251825
ticklocation = _not_none(tickloc=tickloc, ticklocation=ticklocation)
18261826
if ticklocation is not None and ticklocation != 'bottom':
@@ -2833,6 +2833,12 @@ def colorbar(
28332833
# The queue option lets us successively append objects (e.g. line handles)
28342834
# to a list later used for colorbar levels. Same as legend.
28352835
loc = _not_none(loc=loc, location=location)
2836+
orientation = kwargs.get('orientation', None)
2837+
if orientation is not None: # possibly infer loc from orientation
2838+
if orientation not in ('vertical', 'horizontal'):
2839+
raise ValueError(f"Invalid colorbar orientation {orientation!r}. Must be 'vertical' or 'horizontal'.") # noqa: E501
2840+
if loc is None:
2841+
loc = {'vertical': 'right', 'horizontal': 'bottom'}[orientation]
28362842
loc = _translate_loc(loc, 'colorbar', default=rc['colorbar.loc'])
28372843
align = _translate_loc(align, 'panel', default='center', c='center', center='center') # noqa: E501
28382844
kwargs = guides._guide_kw_from_obj(mappable, 'colorbar', kwargs)

0 commit comments

Comments
 (0)