Skip to content

Normalizer with corresponding parameters doesn't work? #689

@munechika-koyo

Description

@munechika-koyo

Summary

Plotting 2D images with the norm parameter and corresponding value limits like vmin, vmax, etc. doesn't work well.

Reproducer

Preamble is

import numpy as np
import ultraplot as uplt

N = 20
state = np.random.RandomState(51423)
data = 11 ** (0.25 * np.cumsum(state.rand(N, N), axis=0))

fig, ax = uplt.subplots()

When specifing vmin like:

ax.pcolormesh(data, cmap="magma", norm="log", vmin=1e-2)

then, we see the following error:

ValueError                                Traceback (most recent call last)
Cell In[110], line 6
      2 state = np.random.RandomState(51423)
      3 data = 11 ** (0.25 * np.cumsum(state.rand(N, N), axis=0))
      4 fig, ax = uplt.subplots()
----> 5 ax.pcolormesh(data, cmap="magma", norm="log", vmin=1e-2)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/internals/inputs.py:405, in _preprocess_or_redirect.<locals>._decorator.<locals>._preprocess_or_redirect(self, *args, **kwargs)
    403     kwargs["color"] = color
    404 # Call main function
--> 405 return func(self, *args, **kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/axes/plot.py:7280, in PlotAxes.pcolormesh(self, x, y, z, **kwargs)
   7278 kw.update(_pop_props(kw, "collection"))
   7279 center_levels = kw.pop("center_levels", None)
-> 7280  kw = self._parse_cmap(
   7281     x, y, z, to_centers=to_centers, center_levels=center_levels, **kw
   7282 )
   7283 edgefix_kw = _pop_params(kw, self._fix_patch_edges)
   7284 labels_kw = _pop_params(kw, self._add_auto_labels)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/internals/warnings.py:119, in _rename_kwargs.<locals>._decorator.<locals>._deprecate_kwargs_wrapper(*args, **kwargs)
    114         key_new = key_new.format(value)
    115     _warn_ultraplot(
    116         f"Keyword {key_old!r} was deprecated in version {version} and may "
    117         f"be removed in {next_release()}. Please use {key_new!r} instead."
    118     )
--> 119 return func_orig(*args, **kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/axes/plot.py:4125, in PlotAxes._parse_cmap(self, cmap, cmap_kw, c, color, colors, norm, norm_kw, extend, vmin, vmax, discrete, default_cmap, default_discrete, skip_autolev, min_levels, plot_lines, plot_contours, center_levels, *args, **kwargs)
   4123 # If norm is given we use it to set vmin and vmax
   4124 if (vmin is not None or vmax is not None) and norm is not None:
-> 4125   raise ValueError("If 'norm' is given, 'vmin' and 'vmax' must not be set.")
   4126 if isinstance(norm, mcolors.Normalize):
   4127     vmin = norm.vmin

ValueError: If 'norm' is given, 'vmin' and 'vmax' must not be set.

Another case like:

ax.pcolormesh(data, cmap="magma", norm=("log", 1e-2))

shows the following error:

TypeError                                 Traceback (most recent call last)
Cell In[111], line 5
      1 N = 20
      2 state = np.random.RandomState(51423)
      3 data = 11 ** (0.25 * np.cumsum(state.rand(N, N), axis=0))
      4 fig, ax = uplt.subplots()
----> 5 ax.pcolormesh(data, cmap="magma", norm=("log", 1e-2))

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/internals/inputs.py:405, in _preprocess_or_redirect.<locals>._decorator.<locals>._preprocess_or_redirect(self, *args, **kwargs)
    403     kwargs["color"] = color
    404 # Call main function
--> 405 return func(self, *args, **kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/axes/plot.py:7280, in PlotAxes.pcolormesh(self, x, y, z, **kwargs)
   7278 kw.update(_pop_props(kw, "collection"))
   7279 center_levels = kw.pop("center_levels", None)
-> 7280 kw = self._parse_cmap(
   7281     x, y, z, to_centers=to_centers, center_levels=center_levels, **kw
   7282 )
   7283 edgefix_kw = _pop_params(kw, self._fix_patch_edges)
   7284 labels_kw = _pop_params(kw, self._add_auto_labels)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/internals/warnings.py:119, in _rename_kwargs.<locals>._decorator.<locals>._deprecate_kwargs_wrapper(*args, **kwargs)
    114         key_new = key_new.format(value)
    115     _warn_ultraplot(
    116         f"Keyword {key_old!r} was deprecated in version {version} and may "
    117         f"be removed in {next_release()}. Please use {key_new!r} instead."
    118     )
--> 119 return func_orig(*args, **kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/axes/plot.py:4249, in PlotAxes._parse_cmap(self, cmap, cmap_kw, c, color, colors, norm, norm_kw, extend, vmin, vmax, discrete, default_cmap, default_discrete, skip_autolev, min_levels, plot_lines, plot_contours, center_levels, *args, **kwargs)
   4247     norm.vmin, norm.vmax = vmin, vmax
   4248 else:
-> 4249    norm = constructor.Norm(norm, vmin=vmin, vmax=vmax, **norm_kw)
   4250 isdiverging = autodiverging and isinstance(norm, pcolors.DivergingNorm)
   4251 if not trues and isdiverging and modes["diverging"] is None:

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/ultraplot/constructor.py:1101, in Norm(norm, *args, **kwargs)
   1099 if norm == "symlog" and not args and "linthresh" not in kwargs:
   1100     kwargs["linthresh"] = 1  # special case, needs argument
-> 1101 return NORMS[norm](*args, **kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/site-packages/matplotlib/colors.py:2651, in _make_norm_from_scale.<locals>.Norm.__init__(self, *args, **kwargs)
   2650 def __init__(self, *args, **kwargs):
-> 2651    ba = bound_init_signature.bind(*args, **kwargs)
   2652     ba.apply_defaults()
   2653     super().__init__(
   2654         **{k: ba.arguments.pop(k) for k in ["vmin", "vmax", "clip"]})

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/inspect.py:3236, in Signature.bind(self, *args, **kwargs)
   3231 def bind(self, /, *args, **kwargs):
   3232     """Get a BoundArguments object, that maps the passed `args`
   3233     and `kwargs` to the function's signature.  Raises `TypeError`
   3234     if the passed arguments can not be bound.
   3235     """
-> 3236   return self._bind(args, kwargs)

File ~/Documents/cherab/iter/.pixi/envs/default/lib/python3.14/inspect.py:3173, in Signature._bind(self, args, kwargs, partial)
   3170                 break
   3172             if param.name in kwargs and param.kind != _POSITIONAL_ONLY:
-> 3173               raise TypeError(
   3174                     'multiple values for argument {arg!r}'.format(
   3175                         arg=param.name)) from None
   3177             arguments[param.name] = arg_val
   3179 # Now, we iterate through the remaining parameters to process
   3180 # keyword arguments

TypeError: multiple values for argument 'vmin'

Is this a bug, or did I mistakenly set it up?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions