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
9 changes: 7 additions & 2 deletions ultraplot/axes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ def _parse_cmap(
Normalize specs.
extend : optional
The colormap extend setting.
vmin, vmax : flaot, optional
vmin, vmax : float, optional
The normalization range.
sequential, diverging, cyclic, qualitative : bool, optional
Toggle various colormap types.
Expand All @@ -2295,6 +2295,12 @@ 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:
raise ValueError("If 'norm' is given, 'vmin' and 'vmax' must not be set.")
if isinstance(norm, mcolors.Normalize):
vmin = norm.vmin
vmax = norm.vmax
vmin = _not_none(vmin=vmin, norm_kw_vmin=norm_kw.pop("vmin", None))
vmax = _not_none(vmax=vmax, norm_kw_vmax=norm_kw.pop("vmax", None))
extend = _not_none(extend, "neither")
Expand Down Expand Up @@ -2440,7 +2446,6 @@ def _parse_cmap(
kwargs.update({"levels": levels, "extend": extend})
else:
guides._add_guide_kw("colorbar", kwargs, extend=extend)

return kwargs

def _parse_cycle(
Expand Down
28 changes: 28 additions & 0 deletions ultraplot/tests/test_1dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,31 @@ def test_triplot_variants(x, y, z, triangles, use_triangulation, use_datadict):
else:
ax.triplot(x, y, "ko-") # Without specific triangles
return fig


@pytest.mark.mpl_image_compare
def test_norm_not_modified():
"""
Ensure that norm is correctly passed to pcolor and related functions.
"""
# Create mock data and assign the colors to y
# The norm should clip the data and not be modified
x = np.arange(10)
y = x**2
c = y
cmap = uplt.Colormap("viridis")
norm = uplt.Norm("linear", 0, 10)
fig, (left, right) = uplt.subplots(ncols=2, share=0)
left.scatter(x, y, c=c, cmap=cmap, norm=norm)
assert norm.vmin == 0
assert norm.vmax == 10

arr = np.random.rand(20, 40) * 1000
xe = np.linspace(0, 1, num=40, endpoint=True)
ye = np.linspace(0, 1, num=20, endpoint=True)

norm = uplt.Norm("linear", vmin=0, vmax=1)
right.pcolor(xe, ye, arr, cmap="viridis", norm=norm)
assert norm.vmin == 0
assert norm.vmax == 1
return fig
Loading