文章詳情頁
python matplotlib繪圖怎么讓每個柱面顏色不一樣?
瀏覽:144日期:2022-07-18 15:54:19
問題描述
def huitu_host(nodes,total): x = np.arange(len(nodes)) plt.figure(figsize=(9,5)) plt.xticks(x,nodes) plt.bar(x,total,width = 0.5,facecolor = ’yellowgreen’,edgecolor = ’white’) for x,y in zip(x,total):plt.text(x,y,’%.f’ % y,ha='center', va='bottom') plt.show() return
問題解答
回答1:color和edgecolor這些都能傳array-like的參數在array里分別指定顏色就好了例子:
x=np.arange(10)y=np.arange(10)plt.bar(x,y,color=[’red’,’green’])
相關文章:
1. 如何解決docker宿主機無法訪問容器中的服務?2. javascript - Web微信聊天輸入框解決方案3. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?4. angular.js - $stateChangeSuccess事件在狀態跳轉的時候不執行?5. javascript - 如何使用nodejs 將.html 文件轉化成canvas6. python - Scrapy存在內存泄漏的問題。7. 如何用筆記本上的apache做微信開發的服務器8. javascript - 螞蟻金服里的react Modal方法,是怎么把元素插入到頁面最后的9. android - rxjava merge 返回Object對象數據如何緩存10. CSS3 畫如下圖形
排行榜
