As I’ve mentioned in the github.
opened 10:26PM - 14 Feb 25 UTC
I already have my color palette stored in sdata.tables["table"].uns, but .pl.ren… der_shapes() ignores it. As a result, I have to manually specify the palette in the function. However, this leads to errors related to invalid hex colors or missing groups.
opened 02:20PM - 28 Jan 25 UTC
When trying to plot a categorical column (say `key`) of `sdata.tables[table_name… ].obs` using spatialdata-plot, colors specified in `sdata.tables[table_name].uns[ "{key}_colors" ]` are ignored due to this line:
https://github.com/scverse/spatialdata-plot/blob/478ab27f9e8a6e06fc28c411e7721f1332b34b66/src/spatialdata_plot/pl/utils.py#L758
This PR fixes this;
https://github.com/scverse/spatialdata-plot/pull/413
Minimal example to reproduce the issue:
```
import numpy as np
import pandas as pd
from anndata import AnnData
from spatialdata import get_element_instances
from spatialdata.datasets import blobs
from spatialdata.models import TableModel
import spatialdata_plot
RNG = np.random.default_rng(seed=42)
labels_name = "blobs_labels"
sdata_blobs = blobs()
instances = get_element_instances(sdata_blobs[labels_name])
n_obs = len(instances)
adata = AnnData(
RNG.normal(size=(n_obs, 10)),
obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"]),
)
adata.obs["instance_id"] = instances.values
adata.obs["category"] = RNG.choice(["a", "b", "c"], size=adata.n_obs)
adata.obs["category"][:3] = ["a", "b", "c"]
adata.obs["region"] = labels_name
table = TableModel.parse(
adata=adata,
region_key="region",
instance_key="instance_id",
region=labels_name,
)
sdata_blobs["other_table"] = table
sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category")
sdata_blobs["other_table"].uns["category_colors"] = ["#800080", "#008000", "#FFFF00"] #purple, green ,yellow
# placeholder, otherwise "category_colors" will be ignored
sdata_blobs["other_table"].uns["category"] = "__value__"
sdata_blobs.pl.render_labels("blobs_labels", color="category").pl.show()
```
With the small fix this gives

I've added a unit test which reproduces the issue in the PR https://github.com/ArneDefauw/spatialdata-plot/blob/5af65aa118f7abf87e47470038ecdbddb27ef1ca/tests/pl/test_render_labels.py#L217
As explained in the PR, I've stumbled upon an issue when trying to plot a subset of the data, trying to maintain the same colors, see https://github.com/ArneDefauw/spatialdata-plot/blob/5af65aa118f7abf87e47470038ecdbddb27ef1ca/tests/pl/test_render_labels.py#L225.
Starting from the code above, if we do:
```
sdata_blobs = bounding_box_query(
sdata_blobs,
axes=("y", "x"),
min_coordinate=[0, 0],
max_coordinate=[100, 100],
target_coordinate_system="global",
)
sdata_blobs.pl.render_labels("blobs_labels", color="category").pl.show()
```
we get:

while we expect

This issue is caused by https://github.com/scverse/spatialdata/blob/03d3be80fad69ff54097e90a9e80ad02e9e0e242/src/spatialdata/_utils.py#L203.
There is a workaround for this:
```
sdata_blobs["other_table"].obs["category"] = (
sdata_blobs["other_table"].obs["category"].cat.remove_unused_categories()
)
```
as documented here https://github.com/ArneDefauw/spatialdata-plot/blob/5af65aa118f7abf87e47470038ecdbddb27ef1ca/tests/pl/test_render_labels.py#L250, but this should probably be documented somewhere public.
opened 10:45AM - 29 Nov 24 UTC
Hi,
An normal hex color is a string include seven chars, such as "#DD4958", but … pl.render_shapes uses nine chars when using datashader, which is not compatible with palette in stored in sdata["table"].uns["leiden_colors"]:

This is my palette:
['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b']
So ian error occurred when using customized palette:

How to plot with our own palette?
Hi, thanks for gathering information across the issues. Working on this is near the top of my todo list (but currently I am working on a few other issues, so it will take a bit).
Meanwhile please complement the issue you opened Really hard to plot categories palette.... · Issue #422 · scverse/spatialdata-plot · GitHub with a working example using the blobs()
dataset, like it is done here: Plot categorical color when colors are provided via .uns · Issue #414 · scverse/spatialdata-plot · GitHub . This will make investigating the issue easier and we generally prioritize issues that are complemented with a minimal reproducible example. Thanks!