Skip to content

Unable to set vmin vmax when plotting vector data #324

Closed

Description

@wangjiawen2013

Hi,
I want set the vmin and vmax of the color, but failed. This is the first method:

norm = matplotlib.colors.Normalize(vmin=-1.0, vmax=0.4)
sdata.pl.render_shapes("cell_circles", norm=norm, color="NOTCH2", method="matplotlib").pl.show(coordinate_systems= "physical", figsize=(10,4))

The resulting plot is here:
image

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:
image

vmin and vmax didn't work in both cases.

Activity

  1. LucaMarconato commented on Aug 16, 2024

    @LucaMarconato
    Member

    Hi, this is related to this #303, please try using clip=True.

  2. wangjiawen2013 commented on Aug 17, 2024

    @wangjiawen2013
    Author

    @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:
    image

    Here is my dataset, there is still no colorbar !

    output

  3. changed the title [-]vmin vmax colorbar[/-] [+]Unable to set vmin vmax when plotting vector data[/+] on Aug 19, 2024
  4. LucaMarconato commented on Aug 19, 2024

    @LucaMarconato
    Member

    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: #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.

  5. olivermccallion commented on Sep 1, 2024

    @olivermccallion

    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?

  6. wangjiawen2013 commented on Sep 2, 2024

    @wangjiawen2013
    Author

    @olivermccallion
    Here is a workaround, spatialdata doesn't support vmin and vmax generally:
    #304

  7. olivermccallion commented on Sep 2, 2024

    @olivermccallion

    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?

  8. wangjiawen2013 commented on Sep 3, 2024

    @wangjiawen2013
    Author

    Unfortunately not. #304 (comment)

  9. self-assigned this
    on Sep 3, 2024
  10. added
    bugSomething isn't working
    shapes 🫧Anything related to Shapes
    on Sep 3, 2024
  11. linked a pull request that will close this issueRefactor of `colorbar` and `norm` logic #346on Sep 4, 2024
  12. wangjiawen2013 commented on Sep 9, 2024

    @wangjiawen2013
    Author

    @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 .

    image

    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.

  13. 5 remaining items

  14. timtreis commented on Sep 10, 2024

    @timtreis
    Member

    Hey @wangjiawen2013,

    if I understand correctly, this is your usecase?

    image

    Or did I misunderstand something?

  15. timtreis commented on Sep 10, 2024

    @timtreis
    Member

    The current norm based approach allows you to make use of the other mpl.colors Normalisation methods, like f.e. this:
    image

  16. wangjiawen2013 commented on Sep 11, 2024

    @wangjiawen2013
    Author

    @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` ?

  17. timtreis commented on Sep 12, 2024

    @timtreis
    Member

    Oh weird, I'd think it should also work for render_shapes. I'll investigate and ping you

  18. added this to the v0.2.7 milestone on Sep 30, 2024
  19. self-assigned this
    on Oct 3, 2024
  20. melonora commented on Oct 3, 2024

    @melonora
    Contributor

    Picking this up today as my first PR getting back to development hehe. Will report back

  21. melonora commented on Oct 3, 2024

    @melonora
    Contributor

    I take it that we should perhaps also add a notebook explaining the matplotlib norm.

  22. LucaMarconato commented on Oct 3, 2024

    @LucaMarconato
    Member

    Agree. We can add this to the static plot workshop notebook and maybe a few extra notebooks in the spatialdata repo.

  23. melonora commented on Oct 3, 2024

    @melonora
    Contributor

    ok fixed it, just testing now, but here already with vmin / vmax / clip and without:
    image

    image

  24. melonora commented on Oct 4, 2024

    @melonora
    Contributor

    @wangjiawen2013 if you would like you can check #368 to see whether it fixes the issue for you. This only fixes it for the matplotlib render. Once the solution is in I will also create a fix for the datashader.

  25. wangjiawen2013 commented on Oct 17, 2024

    @wangjiawen2013
    Author

    @melonora
    Hi,
    I am trying to test it. Is this fixes released in current spatialplot version ?

  26. melonora commented on Oct 21, 2024

    @melonora
    Contributor

    Hi! This is not in the current release yet I believe. Thanks for your willingness to test! If you want you can test from main.

  27. timtreis commented on Oct 21, 2024

    @timtreis
    Member

    Hey @wangjiawen2013, it's not yet released but we'll have one this week that also includes a bunch of datashader fixes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingshapes 🫧Anything related to Shapes

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions