Skip to content

Commit 413e178

Browse files
committed
Pass dual axis arguments through Scale again
1 parent 8245734 commit 413e178

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

docs/axis.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,8 @@
523523
xformatter='null', ylabel='pressure (hPa)',
524524
ylim=(1000, 10), xlocator=[], ycolor=c1, gridcolor=c1
525525
)
526-
scale = plot.Scale('height')
527526
ax.dualy(
528-
scale, label='height (km)', ticks=2.5, color=c2, gridcolor=c2, grid=True
527+
'height', label='height (km)', ticks=2.5, color=c2, gridcolor=c2, grid=True
529528
)
530529

531530
# Height as the linear scale, pressure on opposite axis (scale height 7km)
@@ -534,9 +533,8 @@
534533
xformatter='null', ylabel='height (km)', ylim=(0, 20), xlocator='null',
535534
grid=True, gridcolor=c2, ycolor=c2
536535
)
537-
scale = plot.Scale('pressure')
538536
ax.dualy(
539-
scale, label='pressure (hPa)', locator=100, color=c1, gridcolor=c1, grid=True,
537+
'pressure', label='pressure (hPa)', locator=100, color=c1, gridcolor=c1, grid=True,
540538
)
541539
plot.rc.reset()
542540

@@ -557,13 +555,12 @@
557555
ax.plot(x, response, color=c1, lw=2)
558556

559557
# Add inverse scale to top
560-
scale = plot.Scale('inverse')
561558
ax.format(
562559
xlabel='wavenumber (days$^{-1}$)', ylabel='response', grid=False,
563560
title='Imaginary response function',
564561
suptitle='Duplicate axes with wavenumber and period',
565562
)
566563
ax = ax.dualx(
567-
scale, locator='log', locator_kw={'subs': (1, 2, 5)}, label='period (days)'
564+
'inverse', locator='log', locator_kw={'subs': (1, 2, 5)}, label='period (days)'
568565
)
569566
plot.rc.reset()

proplot/axes/cartesian.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@
7878
7979
Parameters
8080
----------
81-
arg : function, (function, function), or `~matplotlib.scale.ScaleBase`
81+
arg : function, (function, function), or scale-spec
8282
Used to transform units from the parent axis to the secondary axis.
8383
This can be a `~proplot.scale.FuncScale` itself or a function,
84-
(function, function) tuple, or `~matplotlib.scale.ScaleBase` instance used
85-
to *generate* a `~proplot.scale.FuncScale` (see
86-
`~proplot.scale.FuncScale` for details).
84+
(function, function) tuple, or an axis scale specification interpreted
85+
by the `~proplot.constructor.Scale` constructor function, any of which will
86+
be used to build a `~proplot.scale.FuncScale` and applied to the dual axis
87+
(see `~proplot.scale.FuncScale` for details).
8788
{args} : optional
8889
Prepended with ``'{x}'`` and passed to `Axes.format`.
8990
"""

proplot/scale.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,12 @@ def __init__(
281281
``ax.dual%(x)s((lambda x: x**2, lambda x: x**0.5))``.
282282
Again, if the first function is linear or involutory, you do
283283
not need to provide the second!
284-
* A `~matplotlib.scale.ScaleBase` instance, e.g. a scale returned
285-
by the `~proplot.constructor.Scale` constructor function. The
286-
forward transformation, inverse transformation, and default axis
287-
locators and formatters are borrowed from the resulting scale
288-
class. For example, to apply the inverse, use
289-
``ax.dual%(x)s(plot.Scale('inverse'))``.
290-
To apply the base-10 exponential function, use
291-
``ax.dual%(x)s(plot.Scale('exp', 10))``.
284+
* A scale specification interpreted by the `~proplot.constructor.Scale`
285+
constructor function. The forward transformation, inverse transformation,
286+
and default axis locators and formatters are borrowed from the resulting
287+
`~matplotlib.scale.ScaleBase` instance. For example, to apply the
288+
inverse, use ``ax.dual%(x)s('inverse')``. To apply the base-10
289+
exponential function, use ``ax.dual%(x)s(('exp', 10))``.
292290
293291
invert : bool, optional
294292
If ``True``, the forward and inverse functions are *swapped*.
@@ -316,16 +314,18 @@ def __init__(
316314
forward = inverse = arg
317315
elif np.iterable(arg) and len(arg) == 2 and all(map(callable, arg)):
318316
forward, inverse = arg
319-
elif isinstance(arg, mscale.ScaleBase):
320-
trans = arg.get_transform()
317+
else:
318+
from .constructor import Scale
319+
try:
320+
scale = Scale(arg)
321+
except ValueError:
322+
raise ValueError(
323+
'Input should be a function, 2-tuple of forward and and inverse '
324+
f'functions, or an axis scale specification, not {arg!r}.'
325+
)
326+
trans = scale.get_transform()
321327
forward = trans.transform
322328
inverse = trans.inverted().transform
323-
else:
324-
raise ValueError(
325-
'Input should be a function, 2-tuple of forward and '
326-
'and inverse functions, or a matplotlib.scale.ScaleBase '
327-
f'instance, not {arg!r}.'
328-
)
329329

330330
# Create the FuncTransform or composite transform used for this class
331331
# May need to invert functions for dualx() and dualy()

0 commit comments

Comments
 (0)