Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid RGBA argument when use sq.pl.co_occurrence #855

Open
Donbbit opened this issue Jul 23, 2024 · 1 comment
Open

Invalid RGBA argument when use sq.pl.co_occurrence #855

Donbbit opened this issue Jul 23, 2024 · 1 comment
Assignees
Labels
plot 🌺 related to plotting

Comments

@Donbbit
Copy link

Donbbit commented Jul 23, 2024

When I used squidpy to draw Co-occurrence figure:

sq.gr.spatial_neighbors(adata)
sq.gr.nhood_enrichment(adata, cluster_key="Level1_Filt")
sq.pl.nhood_enrichment(adata, cluster_key="Level1_Filt",palette = 'tab20')
sq.gr.co_occurrence(adata, cluster_key="Level1_Filt")
sq.pl.co_occurrence(
adata,
cluster_key="Level1_Filt",
clusters="B",
figsize=(8, 4),
)

I got this error:

ValueError Traceback (most recent call last)
Cell In[115], line 1
----> 1 sq.pl.co_occurrence(
2 adata,
3 cluster_key="Level1_Filt",
4 clusters="B",
5 figsize=(8, 4),
6 )

File /squidpy/lib/python3.10/site-packages/squidpy/pl/_graph.py:365, in co_occurrence(adata, cluster_key, palette, clusters, figsize, dpi, save, legend_kwargs, **kwargs)
362 clusters = _assert_non_empty_sequence(clusters, name="clusters")
363 clusters = sorted(_get_valid_values(clusters, categories))
--> 365 palette = _get_palette(adata, cluster_key=cluster_key, categories=categories, palette=palette)
367 fig, axs = plt.subplots(
368 1,
369 len(clusters),
(...)
372 constrained_layout=True,
373 )
374 axs = np.ravel(axs) # make into iterable

File /squidpy/lib/python3.10/site-packages/squidpy/pl/_color_utils.py:50, in _get_palette(adata, cluster_key, categories, palette, alpha)
45 if len(palette) != len(categories):
46 raise ValueError(
47 f"Expected palette to be of length {len(categories)}, found {len(palette)}. "
48 + f"Removing the colors in adata.uns with adata.uns.pop('{cluster_key}_colors') may help."
49 )
---> 50 return {cat: to_hex(to_rgba(col)[:3] + (alpha,), keep_alpha=True) for cat, col in zip(categories, palette)}
51 except KeyError as e:
52 logg.error(f"Unable to fetch palette, reason: {e}. Using None.")

File /squidpy/lib/python3.10/site-packages/squidpy/pl/_color_utils.py:50, in (.0)
45 if len(palette) != len(categories):
46 raise ValueError(
47 f"Expected palette to be of length {len(categories)}, found {len(palette)}. "
48 + f"Removing the colors in adata.uns with adata.uns.pop('{cluster_key}_colors') may help."
49 )
---> 50 return {cat: to_hex(to_rgba(col)[:3] + (alpha,), keep_alpha=True) for cat, col in zip(categories, palette)}
51 except KeyError as e:
52 logg.error(f"Unable to fetch palette, reason: {e}. Using None.")

File/squidpy/lib/python3.10/site-packages/matplotlib/colors.py:299, in to_rgba(c, alpha)
297 rgba = None
298 if rgba is None: # Suppress exception chaining of cache lookup failure.
--> 299 rgba = _to_rgba_no_colorcycle(c, alpha)
300 try:
301 _colors_full_map.cache[c, alpha] = rgba

File /squidpy/lib/python3.10/site-packages/matplotlib/colors.py:374, in _to_rgba_no_colorcycle(c, alpha)
370 raise ValueError(
371 f"Invalid string grayscale value {orig_c!r}. "
372 f"Value must be within 0-1 range")
373 return c, c, c, alpha if alpha is not None else 1.
--> 374 raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
375 # turn 2-D array into 1-D array
376 if isinstance(c, np.ndarray):

ValueError: Invalid RGBA argument: 'B'

How can I solve this problem?

@giovp giovp added the plot 🌺 related to plotting label Jul 23, 2024
@giovp
Copy link
Member

giovp commented Jul 23, 2024

hi @Donbbit , see the error

 f"Expected palette to be of length {len(categories)}, found {len(palette)}. "

the len of the categories and palette needs to be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plot 🌺 related to plotting
Projects
None yet
Development

No branches or pull requests

2 participants