這期內容當中小編將會給大家?guī)碛嘘P如何在python中使用subplot函數,文章內容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
一、作圖流程:
1.準備數據, , 3作圖, 4定制, 5保存, 6顯示
1.數據可以是numpy數組,也可以是list
2創(chuàng)建畫布:
import matplotlib.pyplot as plt #figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True) #num:圖像編號或名稱,數字為編號 ,字符串為名稱 #figsize:指定figure的寬和高,單位為英寸; #dpi參數指定繪圖對象的分辨率,即每英寸多少個像素,缺省值為80 ,1英寸等于2.5cm,A4紙是 21*30cm的紙張 #facecolor:背景顏色 #edgecolor:邊框顏色 #frameon:是否顯示邊 fig = plt.figure() fig = plt.figure(figsize=(8,6), dpi=80) fig.add_axes() fig, axes = plt.subplos(nrows = 2, ncols = 2) #axes是長度為4的列表
3、作圖路線
一維數據:
axes[0, 0].plot(x, y) axes[0,1].bar([1,2,3], [2,4,8]) axes[0,2].barh([1,2,3], [2,4,8]) axes[1,0].axhline(0.45) axes[1, 1].scatter(x, y) axes[1,2].axvline(0.65) axes[2,0].fill(x,y, color = 'blue') axes[2,1].fill_between(x,y, color = 'blue') axes[2,2].violinplot(y) axes[0,3].arrow(0,0,0.5,0.5) axes[1,3].quiver(x,y)
4, 定制
plt.plot(x,y, alpha=0.4, c = 'blue', maker = 'o') #顏色,標記,透明度 # 顯示數學文本 t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t,s) plt.title(r'$\alpha_i > \beta_i$', fontsize=20) plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_i$', fontsize=20) plt.text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$', fontsize=20) plt.xlabel('time (s)') plt.ylabel('volts (mV)') fig = plt.figure() fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold') ax = fig.add_subplot(111) fig.subplots_adjust(top=0.85) ax.set_title('axes title') ax.set_xlabel('xlabel') ax.set_ylabel('ylabel') ax.text(3, 8, 'boxed italics text in data coords', style='italic', bbox={'facecolor':'red', 'alpha':0.5, 'pad':10}) ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) ax.text(3, 2, u'unicode: Institut f\374r Festk\366rperphysik') ax.text(0.95, 0.01, 'colored text in axes coords', verticalalignment='bottom', horizontalalignment='right', transform=ax.transAxes, color='green', fontsize=15) ax.plot([2], [1], 'o') # 注釋 ax.annotate('我是注釋啦', xy=(2, 1), xytext=(3, 4),color='r',size=15, arrowprops=dict(facecolor='g', shrink=0.05)) ax.axis([0, 10, 0, 10])
5, 保存顯示
plt.savefig("1.png") plt.savefig("1.png", trainsparent =True) plt.show()
二、部分函數使用詳解:
1, fig.add_subplot(numrows, numcols, fignum) ####三個參數,分別代表子圖的行數,列數,圖索引號。 eg: ax = fig.add_subplot(2, 3, 1) (or ,ax = fig.add_subplot(231))
2, plt.subplots()使用
x = np.linspace(0, 2*np.pi,400) y = np.sin(x**2) fig, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple plot') # Creates two subplots and unpacks the output array immediately #fig = plt.figure(figsize=(6,6)) f, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title('Sharing Y axis') ax2.scatter(x, y) # Creates four polar axes, and accesses them through the returned array fig, axes = plt.subplots(2, 2, subplot_kw=dict(polar=True)) axes[0, 0].plot(x, y) axes[1, 1].scatter(x, y) # Share a X axis with each column of subplots plt.subplots(2, 2, sharex='col') # Share a Y axis with each row of subplots plt.subplots(2, 2, sharey='row') # Share both X and Y axes with all subplots plt.subplots(2, 2, sharex='all', sharey='all') # Note that this is the same as plt.subplots(2, 2, sharex=True, sharey=True) # Creates figure number 10 with a single subplot # and clears it if it already exists. fig, ax=plt.subplots(num=10, clear=True)
3.plt.legend()
plt.legend(loc='String or Number', bbox_to_anchor=(num1, num2)) plt.legend(loc='upper center', bbox_to_anchor (0.6,0.95),ncol=3,fancybox=True,shadow=True) #bbox_to_anchor被賦予的二元組中,第一個數值用于控制legend的左右移動,值越大越向右邊移動,第二個數值用于控制legend的上下移動,值越大,越向上移動
1、云計算,典型應用OpenStack。2、WEB前端開發(fā),眾多大型網站均為Python開發(fā)。3.人工智能應用,基于大數據分析和深度學習而發(fā)展出來的人工智能本質上已經無法離開python。4、系統(tǒng)運維工程項目,自動化運維的標配就是python+Django/flask。5、金融理財分析,量化交易,金融分析。6、大數據分析。
上述就是小編為大家分享的如何在python中使用subplot函數了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創(chuàng)新互聯(lián)成都網站設計公司行業(yè)資訊頻道。
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
新聞名稱:如何在python中使用subplot函數-創(chuàng)新互聯(lián)
網頁網址:http://chinadenli.net/article2/ephic.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供關鍵詞優(yōu)化、電子商務、企業(yè)網站制作、網站建設、用戶體驗、移動網站建設
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)