question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

changing color palette for pl.tsne

See original GitHub issue

Hello! 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")

image

But all of these attempts result in the same default cluster color scheme. Any suggestions?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
LuckyMDcommented, Jul 4, 2019

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 call sc.pl.umap(adata, color='louvain') or any other plotting function with color='louvain'.

0reactions
elforecommented, Aug 22, 2019

You can always choose a palTete like ‘Blues’, ‘Reds’, ‘binary’ that will give you a gradient from a clear to a darker color. Maybe that helps but I agree with Philipp, 120 clusters is a lot to visualize with different colors. On Tue, May 28, 2019 at 4:21 PM Philipp A. @.***> wrote: Closed #156 <#156>. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#156?email_source=notifications&email_token=ABF37VNHLRL6TEP3I7BBLEDPXU5X7A5CNFSM4FAIXFAKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGORVQ5OJI#event-2371999525>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF37VNDXU3HBFBIZ6LII73PXU5X7ANCNFSM4FAIXFAA . – Fidel Ramirez

Thanks for your great idea, I will give it a try.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found