Matplotlib实例教程(四)水平条形图
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib实例教程(四)水平条形图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- 🔗 運行環境:python3
- 🚩 作者:K同學啊
- 📚 選自專欄:《Matplotlib教程》
- 🧿 優秀專欄:《Python入門100題》
- 🔥 推薦專欄:《小白入門深度學習》
- 🥇 精選專欄:《深度學習100例》
代碼實現
import numpy as np import matplotlib.pyplot as plt # 支持中文 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用來正常顯示中文標簽 plt.rcParams['axes.unicode_minus'] = False # 用來正常顯示負號high = [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.title("這是標題",fontsize=15) plt.xlabel("x",fontsize=12) plt.ylabel("high",fontsize=12) for x, y in enumerate(high):plt.text(y , x , '%s' % y) #保存圖片 # plt.savefig('test.png') plt.show()總結
以上是生活随笔為你收集整理的Matplotlib实例教程(四)水平条形图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 干!不得不学的算法
- 下一篇: Matplotlib实例教程(六)直方图