Matplotlib 有一些新的且非常方便的颜色图(选项卡颜色图 https://matplotlib.org/examples/color/colormaps_reference.html)。我错过的是生成像 tab20b 或 tab20c 这样的颜色图的功能,但具有三个色调级别而不是四个?
这个解决方案有点复杂,有没有更简单的解决方案?
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)
The colormap in Matplotlib:
编辑:本中提供了更通用的方法SO post https://stackoverflow.com/questions/47222585/matplotlib-generic-colormap-from-tab10.
如果“更容易”指的是更短,则可以直接评估 numpy 数组上的颜色图。
import matplotlib.pyplot as plt
import numpy as np
colors = plt.cm.Vega20c( (4./3*np.arange(20*3/4)).astype(int) )
plt.scatter(np.arange(15),np.ones(15), c=colors, s=180)
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)