文章詳情頁
python matplotlib繪圖怎么讓每個柱面顏色不一樣?
瀏覽:112日期: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’])
相關文章:
排行榜
