Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing tests for norm=Normalize(...) #372

Open
Sonja-Stockhaus opened this issue Oct 16, 2024 · 4 comments
Open

Missing tests for norm=Normalize(...) #372

Sonja-Stockhaus opened this issue Oct 16, 2024 · 4 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@Sonja-Stockhaus
Copy link
Collaborator

Sonja-Stockhaus commented Oct 16, 2024

Currently, we don't have enough tests including the norm=Normalize(...) argument. It should work for matplotlib and also datshader (after #309), but I think we need some more tests and maybe also a bit more documentation.

Also, I noted that both seem to give the same result, not sure if that's a bug

from spatialdata.datasets import blobs
from matplotlib.colors import Normalize
blob=blobs()

blob.pl.render_points(color="instance_id", size=40, norm=Normalize(4, 7, clip=True)).pl.show()
blob.pl.render_points(color="instance_id", size=40, norm=Normalize(4, 7, clip=False)).pl.show()

Image
Image

@Sonja-Stockhaus Sonja-Stockhaus added bug Something isn't working documentation Improvements or additions to documentation labels Oct 16, 2024
@LucaMarconato
Copy link
Member

LucaMarconato commented Jan 5, 2025

Thanks for reporting. The instance_id column has values in [0, 1, ..., 9]. With clip=True one would expect the values [0, 1, 2, 3, 4] to have the same color, and the values [7, 8, 9] to have the same color. So it seems like that there is a bug.

Did you notice this only for matplotlib or also for datashader?

@Sonja-Stockhaus
Copy link
Collaborator Author

When using datashader, both plots look identical as well.

@Sonja-Stockhaus Sonja-Stockhaus self-assigned this Jan 14, 2025
@Sonja-Stockhaus
Copy link
Collaborator Author

After looking into this a bit more, I would say the behavior is not a bug: according to the matplotlib documentation (https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.Normalize.html), with clip=False, values outside of [vmin, vmax] are mapped to values outside [0, 1] (and not exactly to 0 or 1 as would happen with clip=True). Then, the respective colormap can "can mark these under and over values with specific colors".
In the examples above, we use the default colormap viridis, which uses its minimal value for under values and its maximal value for over values (see below).

Image

So, if you would set over and under differently, the result looks like this for clip=False (the clip=True plot looks like above)

from matplotlib import rcParams
import matplotlib

cmap = matplotlib.colormaps[rcParams["image.cmap"]]
cmap.set_under("grey")
cmap.set_over("grey")

blob.pl.render_points(color="instance_id", size=40, norm=Normalize(4, 7, clip=False), cmap=cmap).pl.show()

Image

@LucaMarconato
Copy link
Member

You are right! Thanks for checking this 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy