0
這些選項不工作...如何爲scatter()添加圖例?
import numpy as np
import matplotlib.pyplot as plt
arr = np.random.random((5,3))
ax = plt.axes()
ax.scatter(arr[:,0],arr[:,1],c=['k','r','g','r','b'])
plt.legend(loc='upper left')
plt.draw()
ax = plt.axes()
h = ax.scatter(arr[:,0],arr[:,1],c=['k','r','g','r','b'])
plt.legend(h, loc='upper left')
plt.draw()
我可以組裝使用,而不是陰謀,寫一個循環,
colors = ['k','r','g','r','b']
ax = plt.axes()
h = []
for i,c in enumerate(colors):
h.append(ax.plot(arr[i,0],arr[i,1],c+'o'))
plt.legend(colors) ## plt.legend(h,colors) does not work
plt.draw()
當如果我通過h
到legend
,它說
warnings.warn("Legend does not support %s\nUse proxy artist instead.\n\nhttp://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist\n" % (str(orig_handle),))
但是,我怎樣才能得到這個分散的工作,而不寫一個循環?
謝謝 - 我的替代問題是如何手動建立圖例;就是這個。 – hatmatrix