Last active
April 11, 2024 20:09
-
-
Save jdbcode/33d37999f950a36b43e058d15280b536 to your computer and use it in GitHub Desktop.
Get a list of n hex colors for a given matplotlib palette
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://stackoverflow.com/a/33597599/5391200 | |
from pylab import * | |
cmap = cm.get_cmap('seismic', 5) # matplotlib color palette name, n colors | |
for i in range(cmap.N): | |
rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb | |
print(matplotlib.colors.rgb2hex(rgb)) | |
cmap = cm.get_cmap('plasma', 101) | |
color_list = [matplotlib.colors.rgb2hex(cmap(i)[:3]) for i in range(cmap.N)] | |
print(color_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment