Skip to content

Fix/norm inputs#693

Merged
cvanelteren merged 11 commits intomainfrom
fix/norm-inputs
Apr 20, 2026
Merged

Fix/norm inputs#693
cvanelteren merged 11 commits intomainfrom
fix/norm-inputs

Conversation

@cvanelteren
Copy link
Copy Markdown
Collaborator

@cvanelteren cvanelteren commented Apr 16, 2026

Closes #689

When vmin, vmax is given, norms should not be allowed as inputs (as they are part of the norm object). When strings are given, however, we must allow the logic to run.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/tests/test_colorbar.py 94.28% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Copy Markdown
Collaborator Author

@gepcel @munechika-koyo can this be merged?


@pytest.mark.parametrize(
"norm",
["linear", ["linear"], ("linear",)],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["linear", ["linear"], ("linear",)],
["linear", "log", ["linear"], ("linear",)],

What about trying a different norm?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could; I am currently just testing against the explicit inputs which are str, list or tuple

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that we conducted the type testing there.
It is probably confirmed somewhere that parsing a string and converting it into the corresponding normalizer is possible, so it might not be necessary here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this test

@pytest.mark.parametrize("norm", [uplt.DiscreteNorm, uplt.colors.mcolors.Normalize])
def test_normalize_types(norm):
    data = np.random.rand(10, 10)
    target = norm

    print(norm)
    if norm is uplt.DiscreteNorm:
        norm = uplt.DiscreteNorm(levels=[0, 1])
        discrete = True
    elif norm is uplt.colors.mcolors.Normalize:
        norm = uplt.colors.mcolors.Normalize(vmin=0, vmax=1)
        discrete = False
    else:
        raise ValueError("Norm not understood.")
    fig, ax = uplt.subplots()
    cm = ax.pcolormesh(data, norm=norm, discrete=discrete)
    assert isinstance(cm.norm, target)

@cvanelteren cvanelteren merged commit 8bf6ccb into main Apr 20, 2026
19 checks passed
@cvanelteren cvanelteren deleted the fix/norm-inputs branch April 20, 2026 07:17
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?

3 participants