Matplotlib的subplot函数
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib的subplot函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一:figure
Matplotlib的圖像均位于figure對象中
創建figure:fig = plt.figure()
示例代碼:
# 引入matplotlib包 import matplotlib.pyplot as plt import numpy as np %matplotlib inline #在jupyter notebook 里需要使用這一句命令 # 創建figure對象 fig = plt.figure()運行結果:
<matplotlib.figure.Figure at 0x11a2dd7b8>
二:subplot
fig.add_subplot(a, b, c)
a,b 表示將fig分割成 a*b 的區域
c 表示當前選中要操作的區域,
注意:從1開始編號(不是從0開始)
plot 繪圖的區域是最后一次指定subplot的位置 (jupyter notebook里不能正確顯示)
1)示例一:
代碼:
# 指定切分區域的位置 ax1 = fig.add_subplot(2,2,1) ax2 = fig.add_subplot(2,2,2) ax3 = fig.add_subplot(2,2,3) ax4 = fig.add_subplot(2,2,4)# 在subplot上作圖 random_arr = np.random.randn(100) #print random_arr# 默認是在最后一次使用subplot的位置上作圖,但是在jupyter notebook 里可能顯示有誤 plt.plot(random_arr)# 可以指定在某個或多個subplot位置上作圖 # ax1 = fig.plot(random_arr) # ax2 = fig.plot(random_arr) # ax3 = fig.plot(random_arr)# 顯示繪圖結果 plt.show()2)示例二:
總結
以上是生活随笔為你收集整理的Matplotlib的subplot函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中用什么函数去掉空格_pyt
- 下一篇: 【抖音运营完整篇一】硬性条件过关,抖音视