Skip to content

Fix ValueError when using string norm with vmin/vmax#692

Closed
Ai-chan-0411 wants to merge 1 commit intoUltraplot:mainfrom
Ai-chan-0411:fix/norm-with-vmin-vmax
Closed

Fix ValueError when using string norm with vmin/vmax#692
Ai-chan-0411 wants to merge 1 commit intoUltraplot:mainfrom
Ai-chan-0411:fix/norm-with-vmin-vmax

Conversation

@Ai-chan-0411
Copy link
Copy Markdown

Summary

When calling plotting methods like pcolormesh with a string normalizer (e.g. norm="log") and explicit vmin/vmax limits, the current code raises ValueError: If 'norm' is given, 'vmin' and 'vmax' must not be set. even though this combination is perfectly valid — the string norm needs to be constructed with those limits.

I ran into this while trying to plot log-scaled data with a custom lower bound (vmin=1e-2). The guard in _parse_cmap was checking norm is not None when it should only reject the case where norm is an already-instantiated Normalize object (which carries its own vmin/vmax internally). When norm is a string or tuple, it gets passed to constructor.Norm() later, which accepts vmin/vmax as constructor arguments.

The fix narrows the check to isinstance(norm, mcolors.Normalize) so that string-based norms can coexist with explicit limits. I also added a regression test that confirms pcolormesh(data, norm="log", vmin=1e-2) works without error and the resulting normalizer has the expected vmin.

Fixes #689

The check that rejected vmin/vmax when norm was set was too strict —
it blocked the case where norm is a string like "log" that still needs
vmin/vmax forwarded to the normalizer constructor. The guard now only
fires when norm is an already-instantiated Normalize object, which
carries its own vmin/vmax and would conflict with explicit values.

Fixes Ultraplot#689
@cvanelteren
Copy link
Copy Markdown
Collaborator

#662

@Ai-chan-0411
Copy link
Copy Markdown
Author

Thanks for reviewing and closing this! I appreciate you pointing to PR #662 as the preferred approach for handling this ValueError issue. I'll keep that pattern in mind for future contributions.

@cvanelteren cvanelteren mentioned this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalizer with corresponding parameters doesn't work?

2 participants