Matplotlib实例教程(十一)堆栈图
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib实例教程(十一)堆栈图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- 🔗 運行環境:python3
- 🚩 作者:K同學啊
- 🥇 精選專欄:《深度學習100例》
- 🔥 推薦專欄:《小白入門深度學習》
- 📚 選自專欄:《Matplotlib教程》
- 🧿 優秀專欄:《Python入門100題》
你可能需要安裝的包
- statsmodels
- seaborn
安裝命令(在cmd中輸入該命令即可)
- pip install seaborn
- pip install statsmodels
如果你不知道如何打開命令行,請看這里:如何打開CMD命令行
代碼實現
import pandas as pd import seaborn as sns sns.set_style("white")import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] # 用來正常顯示中文標簽 plt.rcParams['axes.unicode_minus'] = False # 用來正常顯示負號import warnings warnings.filterwarnings("ignore")#忽略警告信息import numpy as np import matplotlib.pyplot as pltx = [1, 2, 3, 4, 5] y1 = [1, 1, 2, 3, 5] y2 = [0, 4, 2, 6, 8] y3 = [1, 3, 5, 7, 9]y = np.vstack([y1, y2, y3])labels = ["A ", "B", "C"]fig, ax = plt.subplots() ax.stackplot(x, y1, y2, y3, labels=labels)# 設置圖例 ax.legend(loc='upper left')# 設置標題 plt.title('堆棧圖 by K同學啊', fontsize=18) plt.show() 👇🏻掃一掃下方二維碼,獲取7900+本電子書👇🏻總結
以上是生活随笔為你收集整理的Matplotlib实例教程(十一)堆栈图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自然语言处理NLP-100例 | 第二篇
- 下一篇: Matplotlib实例教程(十六)3D