我正在处理的数据具有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()
但结果是 TypeError: You must first set_array for mappable
'AxesSubplot' object has no attribute 'colorbar'
。我做完了ax.colorbar()
...我做错了什么?