我正在处理具有3个绘图参数的数据:x,y,c.如何为散点图创建自定义颜色值?
扩展这个例子我试图做:
import matplotlib
import matplotlib.pyplot as plt
cm = matplotlib.cm.get_cmap('RdYlBu')
colors=[cm(1.*i/20) for i in range(20)]
xy = range(20)
plt.subplot(111)
colorlist=[colors[x/2] for x in xy] #actually some other non-linear relationship
plt.scatter(xy, xy, c=colorlist, s=35, vmin=0, vmax=20)
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
但结果是 TypeError: You must first set_array for mappable