TypeError: only size-1 arrays can be converted to Python scalars


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加上就好了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM