日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

莫烦Matplotlib可视化第四章多图合并显示代码学习

發(fā)布時(shí)間:2023/11/29 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 莫烦Matplotlib可视化第四章多图合并显示代码学习 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

4.1Subplot多合一顯示

import matplotlib.pyplot as plt import numpy as npplt.figure() """ 每個(gè)圖占一個(gè)位置 """ # plt.subplot(2,2,1) #將畫(huà)板分成兩行兩列,選取第一個(gè)位置,可以去掉逗號(hào) # plt.plot([0,1],[0,1]) # # plt.subplot(2,2,2) # plt.plot([0,1],[0,1]) # # plt.subplot(2,2,3) # plt.plot([0,1],[0,1]) # # plt.subplot(2,2,4) # plt.plot([0,1],[0,1]) """ 第一個(gè)圖獨(dú)占一行 """ plt.subplot(2,1,1) plt.plot([0,1],[0,1])plt.subplot(2,3,4) plt.plot([0,1],[0,1])plt.subplot(2,3,5) plt.plot([0,1],[0,1])plt.subplot(2,3,6) plt.plot([0,1],[0,1])plt.show()

4.2Subplot分格顯示

import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec """ 三種不同的subplot顯示方法 """# #第一種:subplot2grid # plt.figure() # ax1 = plt.subplot2grid((3,3),(0,0),colspan=3,rowspan=1) #3行3列起始點(diǎn)是0.0,跨度是一行三列 # ax1.plot([1,2],[1,2]) # ax1.set_title('ax1_title') # ax2 = plt.subplot2grid((3,3),(1,0),colspan=2,rowspan=1) #3行3列起始點(diǎn)是0.0,跨度是一行三列 # ax3 = plt.subplot2grid((3,3),(1,2),colspan=1,rowspan=2) # ax4 = plt.subplot2grid((3,3),(2,0),colspan=1,rowspan=1) # ax5 = plt.subplot2grid((3,3),(2,1),colspan=1,rowspan=1)# #第二種:gridspec # plt.figure() # gs = gridspec.GridSpec(3,3) # ax6 = plt.subplot(gs[0,:]) # ax7 = plt.subplot(gs[1,:2]) #第一行占了前兩個(gè)列 # ax8 = plt.subplot(gs[1:,2]) #第一行之后,占第二個(gè)列 # ax9 = plt.subplot(gs[-1,0]) # ax10 = plt.subplot(gs[-1,-2])#第三鐘:define structure f, ((ax11,ax12),(ax21,ax22)) = plt.subplots(2,2,sharex = True,sharey=True) #sharex共享X軸 ax11.scatter ([1,2],[1,2])plt.tight_layout() plt.show()

4.3圖中圖

import matplotlib.pyplot as plt import matplotlib.gridspec as gridspecfig = plt.figure() x = [1,2,3,4,5,6,7] y = [1,3,4,2,5,8,6]left,bottom,width,height = 0.1,0.1,0.8,0.8 ax1 = fig.add_axes([left,bottom,width,height]) ax1.plot(x,y,'r') ax1.set_xlabel('x') ax1.set_ylabel('y') ax1.set_title('title')left,bottom,width,height = 0.2,0.6,0.25,0.25 ax2 = fig.add_axes([left,bottom,width,height]) ax1.plot(x,y,'b') ax1.set_xlabel('x') ax1.set_ylabel('y') ax1.set_title('title inside 1')#第二種畫(huà)圖方法 plt.axes([0.6,0.2,0.25,0.25]) plt.plot(y[::-1],x,'g') plt.xlabel('x') plt.ylabel('y') plt.title('title inside 2')plt.show()

4.4 主次坐標(biāo)軸

import matplotlib.pyplot as plt import numpy as npx = np.arange(0,10,0.1) y1 = 0.05*x**2 y2 = -1*y1fig,ax1 = plt.subplots() ax2 = ax1.twinx() #鏡面Y1軸 ax1.plot(x,y1,'g-') ax2.plot(x,y2,'b--')ax1.set_xlabel('X data') ax1.set_ylabel('Y1',color = 'g') ax2.set_ylabel('Y2',color = 'b')plt.show()

總結(jié)

以上是生活随笔為你收集整理的莫烦Matplotlib可视化第四章多图合并显示代码学习的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。