【发布时间】:2021-07-28 15:47:12
【问题描述】:
我正在处理具有 3 个绘图参数的数据:x、y、c。如何为散点图创建自定义颜色值?
扩展这个example我正在尝试做:
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
【问题讨论】:
标签: python colors matplotlib