ฉันกำลังทำงานกับข้อมูลที่มีข้อมูลที่มีพารามิเตอร์การพล็อต 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()
... ฉันทำอะไรผิด?