changing color palette for pl.tsne
See original GitHub issueHello! I’m trying to recolor some categorical variables in the scanpy.api.pl.tsne function but am having some trouble. Specifically, with continuous data, I’m fine using the color_map
key word to change between scales like “viridis” and “Purples” but when trying to pass the palette
key word for categorical data (sample labels, louvain lables), it doesn’t seem to update the colors in the plot. Perhaps I’m specifying the color palette incorrectly? Here are a few versions I’ve tried:
sc.pl.tsne(adata,
color=['louvain'],
#palette=['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'],
#palette=['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'],
#palette="Set3",
palette=sns.color_palette("hls", 15),
legend_fontsize="20")
But all of these attempts result in the same default cluster color scheme. Any suggestions?
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
changing color palette for pl.tsne · Issue #156 · scverse/scanpy
Hello! I'm trying to recolor some categorical variables in the scanpy.api.pl.tsne function but am having some trouble.
Read more >scanpy.pl.tsne — Scanpy 1.9.1 documentation - Read the Docs
The palette can be a valid ListedColormap name ( 'Set2' , 'tab20' , …), a Cycler object, a dict mapping categories to colors,...
Read more >tSNE coloring v1.0
If the colors are too similar, the palette should be modified (e.g. rotating, or choosing a different colorspace), but if they are similar...
Read more >Specifying color of UMAP cluster - Help - Scanpy - Discourse
When I do this with my data, I get the following error: Please check that the value of 'palette' is a valid matplotlib...
Read more >Palo: spatially aware color palette optimization for single-cell ...
To address this issue, we developed Palo that optimizes the color palette assignment for single-cell and spatial data in a spatially aware manner....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you take a look at
adata.uns['louvain_colors']
you will see this is an ndarray containing hex codes for the colours. So you can change colours manually by e.g.,adata.uns['louvain_colors'][0] = '#ffff00'
. The array is created the first time you callsc.pl.umap(adata, color='louvain')
or any other plotting function withcolor='louvain'
.Thanks for your great idea, I will give it a try.