文章詳情頁
python matplotlib繪圖怎么讓每個柱面顏色不一樣?
瀏覽:109日期: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. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?2. linux運維 - python遠程控制windows如何實現3. javascript - 從mysql獲取json數據,前端怎么處理轉換解析json類型4. django - Python error: [Errno 99] Cannot assign requested address5. android - 安卓做前端,PHP做后臺服務器 有什么需要注意的?6. python小白 關于類里面的方法獲取變量失敗的問題7. mysql - ubuntu開啟3306端口失敗,有什么辦法可以解決?8. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙9. extra沒有加載出來10. python - Scrapy如何得到原始的start_url
排行榜
