新聞中心
說(shuō)明

1、調(diào)用subplot()函數(shù)可以創(chuàng)建子圖,程序可以在子圖上繪制。subplot(nrows、ncols、index、**kwargs)函數(shù)的nrows參數(shù)指定將數(shù)據(jù)圖區(qū)域分成多少行,ncols參數(shù)指定將數(shù)據(jù)圖區(qū)域分成多少列,index參數(shù)指定獲得多少區(qū)域。
2、subplot()函數(shù)還支持直接輸入一個(gè)三位數(shù)的參數(shù),其中第一位數(shù)是nrows參數(shù);第二位數(shù)是ncols參數(shù);第三位數(shù)是index參數(shù)。
參數(shù)
nrows: subplot的行數(shù)
ncols: subplot的列數(shù)
sharex :所有subplot應(yīng)該使用相同的X軸刻度(調(diào)節(jié)xlim將會(huì)影響所有的subplot)
sharey: 所有subplot應(yīng)該使用相同的Y軸刻度(調(diào)節(jié)ylim將會(huì)影響所有的subplot)
subplot_kw: 用于創(chuàng)建各subplot的關(guān)鍵字字典
**fig_kw: 創(chuàng)建figure時(shí)的其他關(guān)鍵字
實(shí)例
import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 100) #作圖1 plt.subplot(2,2,1) #等效于plt.subplot(221) plt.plot(x, x) #作圖2 plt.subplot(2,2,2) plt.plot(x, -x) #作圖3 plt.subplot(2,2,3) plt.plot(x, x ** 2) plt.grid(color='r', linestyle='--', linewidth=1,alpha=0.3) #作圖4 #plt.subplot(224) #plt.plot(x, np.log(x)) plt.show()
以上就是python中subplot函數(shù)畫(huà)圖的方法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中subplot函數(shù)怎么畫(huà)圖?
URL網(wǎng)址:http://m.5511xx.com/article/cceipog.html


咨詢(xún)
建站咨詢(xún)
