补充一个配色网站:
https://materialui.co/colors/
补充别人自己提取的颜色:
https://blog.csdn.net/sinat_41299610/article/details/106912048?spm=1001.2014.3001.5506
直接定义一个类来获取cmap中各个颜色方便使用:
使用的话:mycolor = MyColor(‘Accent’); mycolor.get_color();# 每次就调用获取下一个cmap中的颜色。
class MyColor(object):
def __init__(self, cmap_name):
self.color_set = plt.get_cmap(cmap_name).colors
self.idx = 0
self.color_len = len(self.color_set)
def get_color(self):
if self.idx == self.color_len - 1:
self.idx = 0
color = self.color_set[self.idx]
self.idx += 1
return color
可视化官方提供的cmap
比如查看:[‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’, ‘tab20c’]
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
cmaps = {}
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
def plot_color_gradients(category, cmap_list):
# Create figure and adjust figure height to number of colormaps
nrows = len(cmap_list)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh), dpi=100)
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,
left=0.2, right=0.99)
axs[0].set_title(f'{category} colormaps', fontsize=14)
for ax, name in zip(axs, cmap_list):
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,
transform=ax.transAxes)
# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axs:
ax.set_axis_off()
# Save colormap list for later.
cmaps[category] = cmap_list
plot_color_gradients('Qualitative',
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
'tab20c'])
运行后: