文章詳情頁
python matplotlib繪圖怎么讓每個柱面顏色不一樣?
瀏覽:123日期: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 - log4js的使用問題3. angular.js - angular ng-class里面的引號問題4. javascript - Web微信聊天輸入框解決方案5. javascript - history.replaceState()無法改變query參數6. javascript - Ajax加載Json時,移動端頁面向左上角縮小一截兒,加載完成后才正常顯示,這該如何解決?7. javascript - 移動端textarea不能上下滑動,該怎么解決?8. css - 對于類選擇器使用的問題9. javascript - 為什么form表單提交沒有跨域問題,但ajax提交有跨域問題?10. javascript - 為什么這個點擊事件需要點擊兩次才有效果
排行榜
