Skip to content

Commit fe3ebb6

Browse files
committed
More robust __init__ format() parsing, better obfuscate sig funcs
1 parent ecb6fa3 commit fe3ebb6

8 files changed

Lines changed: 102 additions & 79 deletions

File tree

proplot/axes/base.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Implements basic shared functionality.
55
"""
66
import copy
7+
import inspect
78
import re
89
from numbers import Integral
910

@@ -52,7 +53,6 @@
5253

5354
# A-b-c label string
5455
ABC_STRING = 'abcdefghijklmnopqrstuvwxyz'
55-
5656
# Legned align options
5757
ALIGN_OPTS = {
5858
None: {
@@ -84,18 +84,6 @@
8484
},
8585
}
8686

87-
# Axes init keys. All others are passed to format()
88-
AXES_KEYS = (
89-
'fig',
90-
'rect',
91-
'sharex',
92-
'sharey',
93-
'frameon',
94-
'box_aspect',
95-
'label',
96-
'map_projection',
97-
)
98-
9987

10088
# Projection docstring
10189
_proj_docstring = """
@@ -669,8 +657,12 @@ def __init__(self, *args, **kwargs):
669657
number = kwargs.pop('number', None)
670658
autoshare = kwargs.pop('autoshare', None)
671659
autoshare = _not_none(autoshare, True)
672-
kw_init = {key: kwargs.pop(key) for key in tuple(kwargs) if key in AXES_KEYS}
673-
super().__init__(*args, **kw_init)
660+
rc_kw, rc_mode, kwargs = _parse_format(**kwargs)
661+
kw_format = {}
662+
for sig in (self._format_signature, self._format_signature_base):
663+
if sig is not None:
664+
kw_format.update(_pop_params(kwargs, sig))
665+
super().__init__(*args, **kwargs)
674666

675667
# Varous scalar properties
676668
self._active_cycle = rc['axes.prop_cycle']
@@ -737,9 +729,11 @@ def __init__(self, *args, **kwargs):
737729
self._auto_share()
738730

739731
# Default formatting
740-
# NOTE: rc_mode == 1 applies the proplot settings. This is necessary
741-
# just on the first run. Default calls to format() use rc_mode == 2
742-
self.format(rc_mode=1, skip_figure=True, **kwargs)
732+
# NOTE: This ignores user-input rc_mode. Mode '1' applies proplot
733+
# features which is necessary on first run. Default otherwise is mode '2'
734+
if 'color' in rc_kw:
735+
kw_format['color'] = rc_kw.pop('color') # special case (argument clash)
736+
self.format(rc_kw=rc_kw, rc_mode=1, skip_figure=True, **kw_format)
743737

744738
@staticmethod
745739
def _axisbelow_to_zorder(axisbelow):
@@ -1368,7 +1362,6 @@ def _update_super_labels(self, side, labels=None, **kwargs):
13681362
if labels or kw:
13691363
fig._update_super_labels(side, labels, **kw)
13701364

1371-
@docstring._obfuscate_signature
13721365
@docstring._snippet_manager
13731366
def format(
13741367
self, *, title=None, title_kw=None, abc_kw=None,
@@ -1636,7 +1629,7 @@ def _add_frame(
16361629
patch = mpatches.FancyBboxPatch(
16371630
(xmin, ymin), width, height,
16381631
snap=True,
1639-
zorder=3.5,
1632+
zorder=4.5,
16401633
mutation_scale=fontsize,
16411634
transform=self.transAxes
16421635
)
@@ -1942,8 +1935,9 @@ def _parse_inset_colorbar(
19421935
# Make axes and frame
19431936
from .cartesian import CartesianAxes
19441937
locator = self._make_inset_locator(ibounds, self.transAxes)
1938+
zorder = 5 # NOTE: this is identical to legend zorder
19451939
bbox = locator(None, None)
1946-
ax = CartesianAxes(self.figure, bbox.bounds, zorder=5)
1940+
ax = CartesianAxes(self.figure, bbox.bounds, zorder=zorder)
19471941
ax.set_axes_locator(locator)
19481942
self.add_child_axes(ax)
19491943
kw_frame, kwargs = self._parse_frame('colorbar', **kwargs)
@@ -2311,11 +2305,11 @@ def _draw_colorbar(
23112305
self._register_guide('colorbar', obj, loc) # possibly replace another
23122306
return obj
23132307

2314-
@docstring._obfuscate_signature
2308+
@docstring._obfuscate_params
23152309
@docstring._snippet_manager
23162310
def colorbar(
2317-
self, mappable, values=None, *, loc=None, location=None, queue=False,
2318-
**kwargs
2311+
self, mappable, values=None, *,
2312+
loc=None, location=None, queue=False, **kwargs
23192313
):
23202314
"""
23212315
Add an inset colorbar or an outer colorbar along the edge of the axes.
@@ -2788,11 +2782,11 @@ def _draw_legend(
27882782
self._register_guide('legend', obj, loc) # possibly replace another
27892783
return obj
27902784

2791-
@docstring._concatenate_original
2785+
@docstring._concatenate_inherited # also obfuscates params
27922786
@docstring._snippet_manager
27932787
def legend(
2794-
self, handles=None, labels=None, *, loc=None, location=None, queue=False,
2795-
**kwargs
2788+
self, handles=None, labels=None, *,
2789+
loc=None, location=None, queue=False, **kwargs
27962790
):
27972791
"""
27982792
Add an *inset* legend or *outer* legend along the edge of the axes.
@@ -2853,7 +2847,7 @@ def legend(
28532847
leg = self._draw_legend(handles, labels, loc=loc, **kwargs)
28542848
return leg
28552849

2856-
@docstring._concatenate_original
2850+
@docstring._concatenate_inherited
28572851
@docstring._snippet_manager
28582852
def text(
28592853
self, *args,
@@ -3029,3 +3023,9 @@ def number(self, num):
30293023
self._number = num
30303024
else:
30313025
raise ValueError(f'Invalid number {num!r}. Must be integer >=1.')
3026+
3027+
# Apply signature obfuscation after getting keys
3028+
# NOTE: This is needed for __init__
3029+
_format_signature = None
3030+
_format_signature_base = inspect.signature(format)
3031+
format = docstring._obfuscate_kwargs(format)

proplot/axes/cartesian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,6 @@ def get_tightbbox(self, renderer, *args, **kwargs):
11261126
return super().get_tightbbox(renderer, *args, **kwargs)
11271127

11281128
# Apply signature obfuscation after getting keys
1129-
# NOTE: This is needed for altx/alty keyword parsing
1129+
# NOTE: This is needed for __init__, altx, and alty
11301130
_format_signature = inspect.signature(format)
1131-
format = docstring._obfuscate_signature(format)
1131+
format = docstring._obfuscate_kwargs(format)

proplot/axes/geo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Axes filled with cartographic projections.
44
"""
55
import copy
6+
import inspect
67

78
import matplotlib.axis as maxis
89
import matplotlib.path as mpath
@@ -493,7 +494,6 @@ def _to_label_array(labels, lon=True):
493494

494495
return array
495496

496-
@docstring._obfuscate_signature
497497
@docstring._snippet_manager
498498
def format(
499499
self, *,
@@ -654,6 +654,11 @@ def projection(self, map_projection):
654654
raise ValueError(f'Projection must be a {cls} instance.')
655655
self._map_projection = map_projection
656656

657+
# Apply signature obfuscation after getting keys
658+
# NOTE: This is needed for __init__
659+
_format_signature = inspect.signature(format)
660+
format = docstring._obfuscate_kwargs(format)
661+
657662

658663
class _CartopyAxes(GeoAxes, _GeoAxes):
659664
"""

0 commit comments

Comments
 (0)