Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ultraplot/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import numpy.ma as ma

from . import ticker as pticker
from .internals import ic # noqa: F401
from .internals import _not_none, _version_mpl, warnings
from .internals import (
_not_none,
_version_mpl,
ic, # noqa: F401
warnings,
)

__all__ = [
"CutoffScale",
Expand Down Expand Up @@ -370,7 +374,9 @@ def __init__(self, transform=None, invert=False, parent_scale=None, **kwargs):
kwsym["linthresh"] = inverse(kwsym["linthresh"])
parent_scale = SymmetricalLogScale(**kwsym)
self.functions = (forward, inverse)
self._transform = parent_scale.get_transform() + FuncTransform(forward, inverse)
# Apply the function in data space, then parent scale (e.g., log).
# This ensures dual axes behave correctly when the parent is non-linear.
self._transform = FuncTransform(forward, inverse) + parent_scale.get_transform()

# Apply default locators and formatters
# NOTE: We pass these through contructor functions
Expand Down
18 changes: 18 additions & 0 deletions ultraplot/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import numpy as np
import pytest

import ultraplot as uplt
from ultraplot.internals.warnings import UltraPlotWarning

Expand Down Expand Up @@ -130,6 +131,23 @@ def test_cartesian_format_all_units_types():
ax.format(**kwargs)


def test_dualx_log_transform_is_finite():
"""
Ensure dualx transforms remain finite on log axes.
"""
fig, ax = uplt.subplots()
ax.set_xscale("log")
ax.set_xlim(0.1, 10)
sec = ax.dualx(lambda x: 1 / x)
fig.canvas.draw()

ticks = sec.get_xticks()
assert ticks.size > 0
xy = np.column_stack([ticks, np.zeros_like(ticks)])
transformed = sec.transData.transform(xy)
assert np.isfinite(transformed).all()


def test_axis_access():
# attempt to access the ax object 2d and linearly
fig, ax = uplt.subplots(ncols=2, nrows=2)
Expand Down