Matplotlib有一些新的非常方便的调色板(tab colormap)。我想要的是生成一个类似于tab20b或tab20c的调色板,但只有三个色相级别而不是四个。这个解决方案有点复杂,有没有更简单的方法?
编辑:在这个SO post中提供了更通用的方法。
skip = []
for i in range(0,len(cm.colors)//4+1):
skip.append(4*i)
# the colormap is called Vega in my Matplotlib version
cm = plt.cm.get_cmap('Vega20c')
cm_skip = [cm.colors[i] for i in range(len(cm.colors)) if i not in skip]
for i, c in enumerate(cm_skip):
x = np.linspace(0,1)
y = (i+1)*x + i
plt.plot(x, y, color=c, linewidth=4)
Matplotlib中的色图:
![enter image description here](https://istack.dev59.com/uaJI7.webp)