Skip to content

Commit

Permalink
Merge pull request #317 from pratiman-91/master
Browse files Browse the repository at this point in the history
 adding custom abc and multiple titles #294
  • Loading branch information
lukelbd committed Jan 14, 2022
2 parents d0bc9c0 + b260cab commit 4a3f62a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion WHATSNEW.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Style changes

Features
--------

* Adding custom abc and titles (:pr:`294`) by `Pratiman Patel`.
* Significantly improve "tight layout" performance in geographic plots by skipping
artists with clipping paths/boxes set to the subplot bounds (:commit:`f891e4f0`).
* Add modifiable `proplot.figure.Figure.tight` property to retrieve/change the
Expand Down
18 changes: 11 additions & 7 deletions proplot/axes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
_axes_format_docstring = """
title : str, optional
The axes title.
abc : bool or str, default: :rc:`abc`
abc : bool or str or tuple, default: :rc:`abc`
The "a-b-c" subplot label style. Must contain the character ``a`` or ``A``,
for example ``'a.'``, or ``'A'``. If ``True`` then the default style of
``'a'`` is used. The ``a`` or ``A`` is replaced with the alphabetic character
Expand Down Expand Up @@ -345,10 +345,10 @@
The horizontal padding between a-b-c labels and titles in the same location.
%(units.pt)s
ltitle, ctitle, rtitle, ultitle, uctitle, urtitle, lltitle, lctitle, lrtitle \
: str, optional
: str, tuple, optional
Shorthands for the below keywords.
lefttitle, centertitle, righttitle, upperlefttitle, uppercentertitle, upperrighttitle, \
lowerlefttitle, lowercentertitle, lowerrighttitle : str, optional
lowerlefttitle, lowercentertitle, lowerrighttitle : str, tuple, optional
Additional titles in specific positions. This works as an alternative
to the ``ax.format(title='Title', titleloc=loc)`` workflow and permits
adding more than one title-like label for a single axes.
Expand Down Expand Up @@ -2450,9 +2450,11 @@ def _update_abc(self, **kwargs):
abc = rc.find('abc', context=True) # 1st run, or changed
if abc is True:
abc = 'a'
if abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A".')
if abc and self.number is not None:
if isinstance(abc, tuple):
kw['text'] = abc[self.number - 1]
elif abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A"')
if isinstance(abc, str) and self.number is not None:
nabc, iabc = divmod(self.number - 1, 26)
old = re.search('[aA]', abc).group() # return the *first* 'a' or 'A'
new = (nabc + 1) * ABC_STRING[iabc]
Expand Down Expand Up @@ -2531,7 +2533,9 @@ def _update_title(self, loc, title=None, **kwargs):
# necesssary. For inner panels, use the border and bbox settings.
if loc not in ('left', 'right', 'center'):
kw.update(self._title_border_kwargs)
if title is not None:
if isinstance(title, tuple):
kw['text'] = title[self.number - 1]
elif title is not None:
kw['text'] = title
kw.update(kwargs)
self._title_dict[loc].update(kw)
Expand Down
7 changes: 5 additions & 2 deletions proplot/internals/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ def _validate_abc(value):
Validate a-b-c setting.
"""
try:
return _validate_bool(value)
if type(value) is not tuple:
return _validate_bool(value)
except ValueError:
pass
if isinstance(value, str) and 'a' in value.lower():
return value
raise ValueError("A-b-c specification must be string containing 'a' or 'A'.")
if isinstance(value, tuple):
return value
raise ValueError("A-b-c specification must be string containing 'a' or 'A'")


def _validate_belongs(*options):
Expand Down

0 comments on commit 4a3f62a

Please sign in to comment.