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
5 changes: 5 additions & 0 deletions ultraplot/axes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ def _add_colorbar(
locator = mticker.FixedLocator(ticks)
else:
locator = pticker.DiscreteLocator(ticks)

if tickminor and minorlocator is None:
minorlocator = pticker.DiscreteLocator(ticks, minor=True)

Expand Down Expand Up @@ -1213,6 +1214,10 @@ def _add_colorbar(
# obj.minorlocator = minorlocator # backwards compatibility
obj.update_ticks = guides._update_ticks.__get__(obj) # backwards compatible
if minorlocator is not None:
# Note we make use of mpl's setters and getters
current = obj.minorlocator
if current != minorlocator:
obj.minorlocator = minorlocator
obj.update_ticks()
elif tickminor:
obj.minorticks_on()
Expand Down
17 changes: 17 additions & 0 deletions ultraplot/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,20 @@ def test_reversed_levels():
ax.pcolormesh(data, colorbar="b", **kw)
i += 1
return fig


@pytest.mark.mpl_image_compare
def test_minor_override():
"""Test minor ticks override."""
# Setting a custom minor tick should override the settings. Here we set the ticks to 1 and the minorticks to half that. We then check that the minor ticks are set correctly
data = state.rand(10, 10)
left, right, minor, n = 0, 1, 0.05, 11
levels = np.linspace(left, right, n)
fig, ax = uplt.subplots()
m = ax.pcolormesh(data, colorbar="b", levels=levels)
cax = ax.colorbar(m, minorticks=minor)
assert np.allclose(
cax.minorlocator.tick_values(left, right),
np.linspace(left - minor, right + minor, n * 2 + 1),
)
return fig
Loading