Skip to content

Commit 930e3c6

Browse files
committed
2 parents 5ebc9e1 + 4a3f62a commit 930e3c6

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

WHATSNEW.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Style changes
7171

7272
Features
7373
--------
74-
74+
* Adding custom abc and titles (:pr:`294`) by `Pratiman Patel`.
7575
* Significantly improve "tight layout" performance in geographic plots by skipping
7676
artists with clipping paths/boxes set to the subplot bounds (:commit:`f891e4f0`).
7777
* Add modifiable `proplot.figure.Figure.tight` property to retrieve/change the

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.
@@ -2288,9 +2288,11 @@ def _update_abc(self, **kwargs):
22882288
abc = rc.find('abc', context=True) # 1st run, or changed
22892289
if abc is True:
22902290
abc = 'a'
2291-
if abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
2292-
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A".')
2293-
if abc and self.number is not None:
2291+
if isinstance(abc, tuple):
2292+
kw['text'] = abc[self.number - 1]
2293+
elif abc and (not isinstance(abc, str) or 'a' not in abc and 'A' not in abc):
2294+
raise ValueError(f'Invalid style {abc!r}. Must include letter "a" or "A"')
2295+
if isinstance(abc, str) and self.number is not None:
22942296
nabc, iabc = divmod(self.number - 1, 26)
22952297
old = re.search('[aA]', abc).group() # return the *first* 'a' or 'A'
22962298
new = (nabc + 1) * ABC_STRING[iabc]
@@ -2369,7 +2371,9 @@ def _update_title(self, loc, title=None, **kwargs):
23692371
# necesssary. For inner panels, use the border and bbox settings.
23702372
if loc not in ('left', 'right', 'center'):
23712373
kw.update(self._title_border_kwargs)
2372-
if title is not None:
2374+
if isinstance(title, tuple):
2375+
kw['text'] = title[self.number - 1]
2376+
elif title is not None:
23732377
kw['text'] = title
23742378
kw.update(kwargs)
23752379
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)