Skip to content

Commit 933cec4

Browse files
committed
adding custom abc and multiple titles #294
1 parent d0bc9c0 commit 933cec4

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

proplot/axes/base.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
_axes_format_docstring = """
299299
title : str, optional
300300
The axes title.
301-
abc : bool or str, default: :rc:`abc`
301+
abc : bool or str or tuple, default: :rc:`abc`
302302
The "a-b-c" subplot label style. Must contain the character ``a`` or ``A``,
303303
for example ``'a.'``, or ``'A'``. If ``True`` then the default style of
304304
``'a'`` is used. The ``a`` or ``A`` is replaced with the alphabetic character
@@ -345,10 +345,10 @@
345345
The horizontal padding between a-b-c labels and titles in the same location.
346346
%(units.pt)s
347347
ltitle, ctitle, rtitle, ultitle, uctitle, urtitle, lltitle, lctitle, lrtitle \
348-
: str, optional
348+
: str, tuple, optional
349349
Shorthands for the below keywords.
350350
lefttitle, centertitle, righttitle, upperlefttitle, uppercentertitle, upperrighttitle, \
351-
lowerlefttitle, lowercentertitle, lowerrighttitle : str, optional
351+
lowerlefttitle, lowercentertitle, lowerrighttitle : str, tuple, optional
352352
Additional titles in specific positions. This works as an alternative
353353
to the ``ax.format(title='Title', titleloc=loc)`` workflow and permits
354354
adding more than one title-like label for a single axes.
@@ -2450,9 +2450,11 @@ def _update_abc(self, **kwargs):
24502450
abc = rc.find('abc', context=True) # 1st run, or changed
24512451
if abc is True:
24522452
abc = 'a'
2453-
if abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
2454-
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A".')
2455-
if abc and self.number is not None:
2453+
if isinstance(abc, tuple):
2454+
kw['text'] = abc[self.number - 1]
2455+
elif abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
2456+
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A"')
2457+
if isinstance(abc, str) and self.number is not None:
24562458
nabc, iabc = divmod(self.number - 1, 26)
24572459
old = re.search('[aA]', abc).group() # return the *first* 'a' or 'A'
24582460
new = (nabc + 1) * ABC_STRING[iabc]
@@ -2531,7 +2533,9 @@ def _update_title(self, loc, title=None, **kwargs):
25312533
# necesssary. For inner panels, use the border and bbox settings.
25322534
if loc not in ('left', 'right', 'center'):
25332535
kw.update(self._title_border_kwargs)
2534-
if title is not None:
2536+
if isinstance(title, tuple):
2537+
kw['text'] = title[self.number - 1]
2538+
elif title is not None:
25352539
kw['text'] = title
25362540
kw.update(kwargs)
25372541
self._title_dict[loc].update(kw)

proplot/internals/rcsetup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,15 @@ def _validate_abc(value):
181181
Validate a-b-c setting.
182182
"""
183183
try:
184-
return _validate_bool(value)
184+
if type(value) is not tuple:
185+
return _validate_bool(value)
185186
except ValueError:
186187
pass
187188
if isinstance(value, str) and 'a' in value.lower():
188189
return value
189-
raise ValueError("A-b-c specification must be string containing 'a' or 'A'.")
190+
if isinstance(value, tuple):
191+
return value
192+
raise ValueError("A-b-c specification must be string containing 'a' or 'A'")
190193

191194

192195
def _validate_belongs(*options):

0 commit comments

Comments
 (0)