Python matplotlib實(shí)現(xiàn)多重圖的繪制
from matplotlib import pyplot as plt plt.style.use('fivethirtyeight') fig=plt.figure() ax=fig.add_subplot(1,1,1) plt.text(0.5,0.5,'Figure',ha='center',va='center',size=20,alpha=0.5) # 注:這里的0.5代表x,y軸上面特定的點(diǎn)坐標(biāo),ha和va則代表水平和垂直,ha和va可以確保數(shù)據(jù)絕對(duì)居中 plt.show() xax=ax.xaxis yax=ax.yaxis
Python中插入圖片
在相應(yīng)的目錄下面放上文件:
import numpy as np from PIL import Image plt.figure() plt.xticks([]),plt.yticks([]) im=np.array(Image.open('M.jpg')) plt.imshow(im) plt.show()
繪制子圖
plt.figure() plt.plot([0,1],[0,1]) plt.show()
繪制1*2的子圖
繪制1*2的子圖,類(lèi)似于列向量:
# 1*2 子圖 plt.subplot(2,1,1) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'subplot(2,1,1)',ha='center',va='center',size=20,alpha=0.5) plt.subplot(2,1,2) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'subplot(2,1,2)',ha='center',va='center',size=20,alpha=0.5) plt.show()
plt.subplot(1,2,1) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'subplot(2,1,1)',ha='center',va='center',size=20,alpha=0.5) plt.subplot(1,2,2) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'subplot(2,1,2)',ha='center',va='center',size=20,alpha=0.5) plt.show()
繪制2*2的子圖
## 2*2子圖 plt.style.use('seaborn') fig,axes=plt.subplots(nrows=2,ncols=2) for i,ax in enumerate(axes.flat): print(i) print(ax) plt.show()
plt.style.use('seaborn') fig,axes=plt.subplots(nrows=2,ncols=2) for i,ax in enumerate(axes.flat): ax.set(xticks=[],yticks=[]) s='subplot(2,2)'+str(i)+')' ax.text(0.5,0.5,s,ha='center',va='center',size=20,alpha=0.5) plt.show()
繪制不規(guī)則子圖
不規(guī)則的子圖繪制:
## 不規(guī)則的子圖繪制 import matplotlib.gridspec as gridspec G=gridspec.GridSpec(3,3) ax1=plt.subplot(G[0,:]) plt.show()
## 不規(guī)則的子圖繪制 import matplotlib.gridspec as gridspec G=gridspec.GridSpec(3,3) ax1=plt.subplot(G[0,:]) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'Axes 1',ha='center',va='center',size=20,alpha=0.5) ax2=plt.subplot(G[1,:-1]) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'Axes 2',ha='center',va='center',size=20,alpha=0.5) ax3=plt.subplot(G[1:,-1]) plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'Axes 3',ha='center',va='center',size=20,alpha=0.5) ax4=plt.subplot(G[-1,0]) # 表示倒數(shù)第一行和第一列 plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'Axes 4',ha='center',va='center',size=20,alpha=0.5) ax5=plt.subplot(G[-1,1]) # 表示倒數(shù)第一行和第二列 plt.xticks([]),plt.yticks([]) plt.text(0.5,0.5,'Axes 5',ha='center',va='center',size=20,alpha=0.5) plt.show()
繪制圖中代碼
fig,ax=plt.subplots()?。!⊥瑫r(shí)生成圖和坐標(biāo)系 ax.set(xticks=[],yticks=[]) s='Style 1\n\nfig,ax=plt.subplots()\nax.plot()' ax.text(0.5,0.5,s,ha='center',va='center',size=20,alpha=0.5)
fig=plt.figure() # 先生成圖再生成坐標(biāo)系 ax=fig.add_subplot(1,1,1) ax.set(xticks=[],yticks=[]) s='Style 2\n\nfig,ax=plt.subplots()\nax.plot()' ax.text(0.5,0.5,s,ha='center',va='center',size=20,alpha=0.5)
到此這篇關(guān)于Python matplotlib實(shí)現(xiàn)多重圖的繪制的文章就介紹到這了,更多相關(guān)Python matplotlib多重圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python 常用日期處理 -- calendar 與 dateutil 模塊的使用
這篇文章主要介紹了Python如何使用calendar 與 dateutil 模塊處理日期,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下2020-09-09jupyter notebook 寫(xiě)代碼自動(dòng)補(bǔ)全的實(shí)現(xiàn)
這篇文章主要介紹了jupyter notebook 寫(xiě)代碼自動(dòng)補(bǔ)全的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11創(chuàng)建Django項(xiàng)目圖文實(shí)例詳解
這篇文章主要介紹了創(chuàng)建Django項(xiàng)目,結(jié)合圖文與實(shí)例形式詳細(xì)分析了Django項(xiàng)目創(chuàng)建的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2019-06-06Python基于回溯法子集樹(shù)模板解決取物搭配問(wèn)題實(shí)例
這篇文章主要介紹了Python基于回溯法子集樹(shù)模板解決取物搭配問(wèn)題,簡(jiǎn)單描述了搭配問(wèn)題并結(jié)合實(shí)例形式分析了Python使用回溯法子集樹(shù)模板解決取物搭配問(wèn)題的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-09-09Tensorflow與Keras自適應(yīng)使用顯存方式
這篇文章主要介紹了Tensorflow與Keras自適應(yīng)使用顯存方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06Flask框架運(yùn)用Ajax實(shí)現(xiàn)輪詢(xún)動(dòng)態(tài)繪圖
Ajax是異步JavaScript和XML可用于前后端交互,本文將通過(guò)Ajax輪詢(xún)獲取后端的數(shù)據(jù),前臺(tái)使用echart繪圖庫(kù)進(jìn)行圖形的生成與展示,最后實(shí)現(xiàn)動(dòng)態(tài)監(jiān)控內(nèi)存利用率的這個(gè)功能,需要的可以參考一下2022-11-11