Skip to content
Merged
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
7 changes: 7 additions & 0 deletions ultraplot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,13 @@ def _get_tickline_props(self, axis=None, which="major", native=True, rebuild=Fal
context = not rebuild and (native or self._context_mode == 2)
kwticks = self.category(f"{axis}tick.{which}", context=context)
kwticks.pop("visible", None)

# NOTE: We pop visibility properties from the styling dictionary so that
# stylistic updates (like applying a dark_background theme) do not override
# the tick visibility logic strictly managed by ax._update_locs() and alternate axes.
for key in ("bottom", "top", "left", "right"):
kwticks.pop(key, None)

for key in ("color", "direction"):
value = self.find(f"{axis}tick.{key}", context=context)
if value is not None:
Expand Down
45 changes: 45 additions & 0 deletions ultraplot/tests/test_axes_alt_styles.py
Copy link
Copy Markdown

@munechika-koyo munechika-koyo May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check whether each axis's color is correct, not just visibility?
Checking t.get_color() == #xxxxxx, ax.yaxis.label.get_color() == #xxxxxx, ax.spines["left"].get_edgecolor() == (x, x, x, 1.0), etc. should be useful.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
import ultraplot as uplt


def test_alt_axes_styling_dark_background():
"""
Test that applying dark_background style does not leak tick visibility
settings and correctly preserves alternative axes tick locations.
"""
with uplt.rc.context(style="dark_background"):
fig, ax = uplt.subplots()
ax.format(ycolor="C0", ylabel="Left Axis")

ax2 = ax.alty(color="C1")
ax2.format(ycolor="C1", ylabel="Right Axis", ylim=(0, 1))

# The left axis should ONLY have visible ticks on the left
left_ax_left_ticks = sum(
1
for t in ax.yaxis.get_ticklines()
if t.get_visible() and t.get_xdata()[0] == 0
)
left_ax_right_ticks = sum(
1
for t in ax.yaxis.get_ticklines()
if t.get_visible() and t.get_xdata()[0] == 1
)

# The right axis (ax2) should ONLY have visible ticks on the right
right_ax_left_ticks = sum(
1
for t in ax2.yaxis.get_ticklines()
if t.get_visible() and t.get_xdata()[0] == 0
)
right_ax_right_ticks = sum(
1
for t in ax2.yaxis.get_ticklines()
if t.get_visible() and t.get_xdata()[0] == 1
)

assert left_ax_left_ticks > 0, "Left axis should have left ticks"
assert left_ax_right_ticks == 0, "Left axis should NOT have right ticks"

assert right_ax_left_ticks == 0, "Right axis should NOT have left ticks"
assert right_ax_right_ticks > 0, "Right axis should have right ticks"
Loading