Skip to content
Closed
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
6 changes: 4 additions & 2 deletions ultraplot/axes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4120,8 +4120,10 @@ def _parse_cmap(
# Parse keyword args
cmap_kw = cmap_kw or {}
norm_kw = norm_kw or {}
# If norm is given we use it to set vmin and vmax
if (vmin is not None or vmax is not None) and norm is not None:
# If norm is an already-instantiated Normalize, extract vmin/vmax from it.
# When norm is a string or tuple it will be constructed later with the
# supplied vmin/vmax, so we must not reject them here.
if (vmin is not None or vmax is not None) and isinstance(norm, mcolors.Normalize):
raise ValueError("If 'norm' is given, 'vmin' and 'vmax' must not be set.")
if isinstance(norm, mcolors.Normalize):
vmin = norm.vmin
Expand Down
13 changes: 13 additions & 0 deletions ultraplot/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,19 @@ def test_pie_labeled_series_in_dataframes():
uplt.close(fig)


def test_string_norm_with_vmin_vmax(rng):
"""
When norm is a string (e.g. 'log'), vmin and vmax should be forwarded
to the normalizer constructor instead of raising ValueError.
Regression test for https://github.com/Ultraplot/UltraPlot/issues/689
"""
data = 11 ** (0.25 * np.cumsum(rng.random((20, 20)), axis=0))
fig, ax = uplt.subplots()
m = ax.pcolormesh(data, cmap="magma", norm="log", vmin=1e-2)
assert m.norm.vmin == pytest.approx(1e-2)
uplt.close(fig)


def test_color_parsing_for_none():
"""
Ensure that none is not parsed to white
Expand Down