Matplotlib-barh-绘制水平条形图
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib-barh-绘制水平条形图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import numpy as np
import matplotlib.pyplot as plthigh = [5,1,4,5.6,2,4,6.2,1.3,6,2]
x = ["a","b","c","d","e","f","g","h","i","j"]
"""
繪制水平條形圖方法barh
參數一:y軸
參數二:x軸
"""
plt.barh(range(10), high, height=0.7, color=['r','b','y','green'], alpha=0.8) # 從下往上畫
plt.yticks(range(10), x)
plt.xlim(0,7)
plt.xlabel("x")
plt.ylabel("high")
for x, y in enumerate(high):plt.text(y , x , '%s' % y)
#保存圖片
plt.savefig(r'C:\Users\Administrator\Desktop\test.png')
plt.show()
總結
以上是生活随笔為你收集整理的Matplotlib-barh-绘制水平条形图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 列表和字典之间的相互转换-Python3
- 下一篇: Matplotlib-动态更新图表