Skip to content

Legend coloring doesn't match with plot in render_shapes #104

Closed

Description

@timtreis

MRE

f, ax = plt.subplots(figsize=(7, 7))
sdata_ST8059048.pl.render_shapes(color="library", palette="Pastel1").pl.show(ax=ax)
cropped_sdata.pl.render_shapes(color="Sox2").pl.show(ax=ax, colorbar=False)

# show the spatial query bounding box
rect = patches.Rectangle((8000, 12000), 4000, 4000, linewidth=5, edgecolor="k", facecolor="none")
ax.add_patch(rect)

image

Activity

  1. self-assigned this
    on Jun 14, 2023
  2. LucaMarconato commented on Jun 20, 2023

    @LucaMarconato
    Member

    I also noticed that in the new aggregation notebook.

    I define some categorical annotations: "categorical": ["a", "a", "b", "c", "d"],, but when I plot them the a category is colored only once, while the d is colored twice.

    import numpy as np
    import pandas as pd
    from anndata import AnnData
    from numpy.random import default_rng
    from spatialdata import SpatialData
    import spatialdata_plot
    from spatialdata.models import TableModel
    from spatialdata.datasets import blobs
    
    RNG = default_rng(42)
    
    adata_circles = AnnData(
        RNG.normal(size=(5, 3)),
        var=pd.DataFrame(index=["gene_h", "gene_k", "gene_l"]),
        obs=pd.DataFrame(
            {
                "categorical": ["a", "a", "b", "c", "d"],
                "region": "blobs_circles",
                "instance_id": np.arange(5),
            }
        ),
    )
    sdata = blobs()
    adata_circles.obs["categorical"] = adata_circles.obs["categorical"].astype("category")
    adata_circles.obs["region"] = adata_circles.obs["region"].astype("category")
    adata_circles = TableModel.parse(adata_circles, region="blobs_circles", region_key="region", instance_key="instance_id")
    sdata_circles = SpatialData(shapes={"blobs_circles": sdata["blobs_circles"]}, table=adata_circles)
    
    # let's add two numerical columns to the GeoDataFrame
    sdata_circles["blobs_circles"]["feature_m"] = RNG.normal(size=(5))
    sdata_circles["blobs_circles"]["feature_n"] = RNG.normal(size=(5))
    
    print(sdata_circles.table.obs.categorical)
    
    # sdata_circles.pl.render_shapes(color="categorical").pl.show(title="categorical")
    

    image

    image
  3. linked a pull request that will close this issueLegend order is now deterministic #143on Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions