Skip to content

Discussion: add title to multiple colorbars? #361

Description

@LucaMarconato
##
from spatialdata.datasets import blobs
import spatialdata_plot
import matplotlib.pyplot as plt

sdata = blobs()
sdata['blobs_polygons']['column'] = 0

(
    sdata.pl.render_images('blobs_image')
    .pl.render_shapes('blobs_circles', color='radius')
    .pl.render_shapes('blobs_polygons', color='column')
    .pl.show()
)
plt.show()

gives
image
Which looks great! But it may be confusing to know which colorbar refers to what. I would consider one of the following:

  1. we leave it as it is: the user should use different colorbars (e.g. viridis + gray) when plotting multiple elements at the same time, so the ambiguity doesn't exist
  2. we add a title on top of the colorbar to make clear what the colorbar refers to
  3. we show only one colorbar maximum.

I prefer having multiple colorbar, so I'd choose either 1 or 2. @timtreis @Sonja-Stockhaus wdyt?

Activity

  1. timtreis commented on Sep 27, 2024

    @timtreis
    Member

    Don't like 3) either.

    Vaguely related to #349 in which I have to refactor the entire logic anyway. One option would be to add cbar_title to the individual calls

  2. timtreis commented on Mar 29, 2026

    @timtreis
    Member

    Now possible with #518

    from spatialdata.datasets import blobs
    import spatialdata_plot
    import matplotlib.pyplot as plt
    
    sdata = blobs()
    sdata["blobs_polygons"]["column"] = range(len(sdata["blobs_polygons"]))
    
    # Default: column name becomes colorbar label automatically
    (
          sdata.pl.render_images("blobs_image")
          .pl.render_shapes("blobs_circles", color="radius")
          .pl.render_shapes("blobs_polygons", color="column")
          .pl.show()
    )
    
    Image
    # Custom labels via colorbar_params
    (
          sdata.pl.render_images("blobs_image")
          .pl.render_shapes("blobs_circles", color="radius", colorbar_params={"label": "Circle radius"})
          .pl.render_shapes("blobs_polygons", color="column", colorbar_params={"label": "Polygon ID"})
          .pl.show()
    )
    
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions