Traceback (most recent call last):
File "/Users/mac126/數據分析/mayplotlib/mayplotlib.py", line 50, in <module>
plt.text(x,y ,'%.2f'%y ,ha='center',va='bottom')
TypeError: only size-1 arrays can be converted to Python scalars
源碼
import matplotlib.pyplot as plt import numpy as np k=10 x=np.arange(k) y=np.random.rand(k) plt.bar(x,y) for x in zip(x,y): plt.text(x,y ,'%.2f'%y ,ha='center',va='bottom') plt.show()
發現是少了一個參數y加上就好了

