How to make a color map with many unique colors in seaborn

2024/11/13 18:46:11

I want to make a colormap with many (in the order of hundreds) unique colors.

This code:

custom_palette = sns.color_palette("Paired", 12)
sns.palplot(custom_palette)

returns a palplot with 12 unique colors.
But this code:

custom_palette = sns.color_palette("Paired", 24)
sns.palplot(custom_palette)

returns a palplot with 12 unique colors, seemingly repeated twice.

How do I obtain 24 (or more) unique colors?

Answer

There is definitely a way to get what you want! Fortunately, Seaborn has the ability to read colorcet palettes which have some nice options for getting a wider range of qualitative colors:

from sklearn.datasets import make_blobs
import colorcet as cc
import matplotlib.pyplot as plt
import seaborn as snsblobs, labels = make_blobs(n_samples=1000, centers=25, center_box=(-100, 100))
palette = sns.color_palette(cc.glasbey, n_colors=25)sns.scatterplot(x=blobs[:,0], y=blobs[:, 1], hue=labels, data=blobs, palette=palette)
plt.legend(ncol=5, bbox_to_anchor=(1, 1))
plt.show()

Results in the following graph with 25 distinct colors:

enter image description here

Hope this helps!

https://en.xdnf.cn/q/72006.html

Related Q&A

Swap column values based on a condition in pandas

I would like to relocate columns by condition. In case country is Japan, I need to relocate last_name and first_name reverse.df = pd.DataFrame([[France,Kylian, Mbappe],[Japan,Hiroyuki, Tajima],[Japan,…

How to improve performance on a lambda function on a massive dataframe

I have a df with over hundreds of millions of rows.latitude longitude time VAL 0 -39.20000076293945312500 140.80000305175781250000 1…

How to detect if text is rotated 180 degrees or flipped upside down

I am working on a text recognition project. There is a chance the text is rotated 180 degrees. I have tried tesseract-ocr on terminal, but no luck. Is there any way to detect it and correct it? An exa…

Infinite loops using for in Python [duplicate]

This question already has answers here:Is there an expression for an infinite iterator?(7 answers)Closed 5 years ago.Why does this not create an infinite loop? a=5 for i in range(1,a):print(i)a=a+1or…

How to print the percentage of zipping a file python

I would like to get the percentage a file is at while zipping it. For instance it will print 1%, 2%, 3%, etc. I have no idea on where to start. How would I go about doing this right now I just have the…

kafka-python read from last produced message after a consumer restart

i am using kafka-python to consume messages from a kafka queue (kafka version 0.10.2.0). In particular i am using KafkaConsumer type. If the consumer stops and after a while it is restarted i would lik…

Python lib to Read a Flash swf Format File

Im interested in using Python to hack on the data in Flash swf files. There is good documentation available on the format of swf files, and I am considering writing my own Python lib to parse that dat…

PyQt5 Signals and Threading

I watched a short tutorial on PyQt4 signals on youtube and am having trouble getting a small sample program running. How do I connect my signal being emitted from a thread to the main window?import cp…

Pythons hasattr sometimes returns incorrect results

Why does hasattr say that the instance doesnt have a foo attribute?>>> class A(object): ... @property ... def foo(self): ... ErrorErrorError ... >>> a = A() >>…

Pure python library to read and write jpeg format

guys! Im looking for pure python implementation of jpeg writing (reading will be nice, but not necessary) library. Ive founded only TonyJPEG library port at http://mail.python.org/pipermail/image-sig/2…