Open wangjiawen2013 opened 4 weeks ago
Hi, this is related to this https://github.com/scverse/spatialdata-plot/issues/303, please try using clip=True
.
@LucaMarconato
vmin and max only works for pl.render_images
, but don't work for pl.render_shapes
. And, even for pl.render_images
, there is no colorbar at all ! As you can see from the spatialdata xenium tutorial:
Here is my dataset, there is still no colorbar !
Thanks for the observation. I have changed the title to emphasize that the issue is also open for vector data (the linked issue is indeed for raster data). Regarding the missing colorbar, I already reported the issue here: https://github.com/scverse/spatialdata-plot/issues/304, so we can follow up there. The developer assigned to the issue is temporarily not available for the next 14 days because of a pressing deadline.
Running into the same problem with spatialdata-plot version 0.2.6.dev3+gffd4a1f where:
region.pl.render_shapes(
"cell_boundaries", color = "CD3E", vmax = 11, clip=True).pl.show(title="CD3", coordinate_systems="global", ax=axes[1])
region.pl.render_shapes(
"cell_boundaries", color = "CD3E", vmax = 11).pl.show(title="CD3", coordinate_systems="global", ax=axes[1])
and
norm = matplotlib.colors.Normalize(vmin=0.0, vmax=2000)
region.pl.render_shapes(
"cell_boundaries", color = "CD3E", norm=norm, clip=True).pl.show(title="CD3", coordinate_systems="global", ax=axes[1])
do not alter the colorbar limits / shape shading. Is there any update on the best way to fix this?
@olivermccallion Here is a workaround, spatialdata doesn't support vmin and vmax generally: https://github.com/scverse/spatialdata-plot/issues/304
Thanks @wangjiawen2013
I'm trying to achieve the same behaviour as your opening post, where you were looking to specify min and max values to the render_shapes() colorbar when the shapes are shaded by a particular feature -- not so worried about having a color bar for raster data / render_images(). #304 seems to be a work around for this second issue. Is there a solution/workaround for the first?
@timtreis @olivermccallion
I have tested the latest spatialdata-plot (v0.2.6)
vmin
and vmax
works only in pl.render_images
, but still don't work in pl.render_shapes
.
As you can see, vmin and vmax changed the min and max number on the colorbar, but the color in the figures was not changed at all ! It is expected to be more brighter when decreasing vmax, which is the case in pl.render_images
.
I'm surprised it even works in render_images :D Thought I had removed it. Could you try creating a matplotlib Normalise object with your desired vmin/vmax values and pass that to norm
? That should work
@timtreis I would either remove vmin
vmax
, or create a Normalise
object if vmin
vmax
are passed.
Will check later but I do think we did remove them when migrating to the norm
-based logic. I'd be tentatively against accepting both as input because then we have a lot of ambiguity beween cmap, norm and whatever other things the user specifies. If we just take in a matplotlib.colors.Normalise
object, it's definite.
I think you should keep vmin
and vmax
. We can use these two parameters to clip/truncate the colorbar to make the figure more saturated. It's different from norm
. We use norm
to normalize the colorbar, but don't clip/truncate it. So vmin/vmax
have different functions with norm
. Sometimes we need to use vmin/vmax
to beautify the figure, but sometimes we need norm
.
I'm surprised it even works in render_images :D Thought I had removed it. Could you try creating a matplotlib Normalise object with your desired vmin/vmax values and pass that to
norm
? That should work
We created a matplotlib Normalise object with the desired vmin/vmax values and pass that to norm
, but this is not what we need. What we need is to clip/truncate the colorbar, not normalization. Maybe you can refer to scanpy (such as help(sc.pl.umap)
for vmin
and vmax
.
Hey @wangjiawen2013,
if I understand correctly, this is your usecase?
Or did I misunderstand something?
The current norm
based approach allows you to make use of the other mpl.colors
Normalisation methods, like f.e. this:
@timtreis
Yes, this is what I mean ! I am not familiar with matplotlib norm
and don't know the clip
parameter. I tested my data and found this works in pl.render_images
, while don't work for pl.render_shapes
, could you extend norm
to pl.render_shapes` ?
Oh weird, I'd think it should also work for render_shapes
. I'll investigate and ping you
Hi, I want set the vmin and vmax of the color, but failed. This is the first method:
The resulting plot is here:
This is the second method:
sdata.pl.render_shapes("cell_circles", vmin=-1, vmax=1, color="NOTCH2", method="matplotlib").pl.show(coordinate_systems= "physical", figsize=(10,4))
The resulting plot is here:vmin
andvmax
didn't work in both cases.