文章詳情頁
python matplotlib繪圖怎么讓每個柱面顏色不一樣?
瀏覽:129日期: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的參數(shù)在array里分別指定顏色就好了例子:
x=np.arange(10)y=np.arange(10)plt.bar(x,y,color=[’red’,’green’])
相關(guān)文章:
1. mysql - 在不允許改動數(shù)據(jù)表的情況下,如何優(yōu)化以varchar格式存儲的時間的比較?2. javascript - Img.complete和img.onload判斷圖片加載完成有什么區(qū)別?3. java中返回一個對象,和輸出對像的值,意義在哪兒4. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?5. css3 - 純css實現(xiàn)點擊特效6. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么?7. css - 網(wǎng)頁div區(qū)塊 像蘋果一樣可左右滑動 手機(jī)與電腦8. 安全性測試 - nodejs中如何防m(xù)ySQL注入9. javascript - 關(guān)于apply()與call()的問題10. python - 在sqlalchemy中獲取剛插入的數(shù)據(jù)id?
排行榜

熱門標(biāo)簽