Skip to content

Showing legend by defaults and allowing richer customizability #459

Closed

Description

@LucaMarconato

From @MeyerBender:

  • legends: in my opinion, it would be great to show legends for the channels by default. Alternatively, one could consider implementing something like pl.render_legend() to give full customizability to the user.

This is an example of plot from spatialproteomics. Notebook here.

Image

and the same plot from spatialdata. Notebook here

Image

Activity

  1. MeyerBender commented on May 14, 2025

    @MeyerBender
    Contributor

    Example code snippet.

    import spatialdata as sd
    import spatialdata_plot
    import matplotlib.pyplot as plt
    import numpy as np
    
    # example data
    image = sd.models.Image2DModel.parse(
        np.random.rand(4, 100, 100), transformations=None, dims=("c", "x", "y"), c_coords=["DAPI", "CD4", "CD8", "FOXP3"]
    )
    sdata = sd.SpatialData(images={"image": image})
    
    fig, ax = plt.subplots(1, 2)
    
    # plotting a single channel
    sdata.pl.render_images(channel='DAPI').pl.show(ax=ax[0])
    
    # plotting multiple channels
    sdata.pl.render_images(channel=['CD4', 'CD8', 'FOXP3']).pl.show(ax=ax[1])
    

    Currently returns this:

    Image
  2. timtreis commented on Apr 4, 2026

    @timtreis
    Member

    Hey @MeyerBender, does #576 address your feature request?

  3. MeyerBender commented on Apr 7, 2026

    @MeyerBender
    Contributor

    Hi @timtreis, yes, this is looking really good! One minor thing, I think if you call it channels_as_categories, it needs to be really clear what it does in the docs. Wondering if calling it something like legend or channel_legend would make more sense, but that might be confusing with the colorbar argument for single-channel images...

  4. timtreis commented on Apr 7, 2026

    @timtreis
    Member

    How about channels_as_legend?

  5. MeyerBender commented on Apr 8, 2026

    @MeyerBender
    Contributor

    Yeah that works :)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions