python繪制三維圖的詳細新手教程_第1頁
python繪制三維圖的詳細新手教程_第2頁
python繪制三維圖的詳細新手教程_第3頁
python繪制三維圖的詳細新手教程_第4頁
python繪制三維圖的詳細新手教程_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

第python繪制三維圖的詳細新手教程#Makeradiiandanglesspaces(radiusr=0omittedtoeliminateduplication).

radii=np.linspace(0.125,1.0,n_radii)

angles=np.linspace(0,2*np.pi,n_angles,endpoint=False)

#Repeatallanglesforeachradius.

angles=np.repeat(angles[...,np.newaxis],n_radii,axis=1)

#Convertpolar(radii,angles)coordstocartesian(x,y)coords.

#(0,0)ismanuallyaddedatthisstage,sotherewillbenoduplicate

#pointsinthe(x,y)plane.

x=np.append(0,(radii*np.cos(angles)).flatten())

y=np.append(0,(radii*np.sin(angles)).flatten())

#Computeztomakethepringlesurface.

z=np.sin(-x*y)

fig=plt.figure()

ax=fig.gca(projection='3d')

ax.plot_trisurf(x,y,z,linewidth=0.2,antialiased=True)

plt.show()

七、等高線(Contourplots)

基本用法:

ax.contour(X,Y,Z,*args,**kwargs)

code:

frommpl_toolkits.mplot3dimportaxes3d

importmatplotlib.pyplotasplt

frommatplotlibimportcm

fig=plt.figure()

ax=fig.add_subplot(111,projection='3d')

X,Y,Z=axes3d.get_test_data(0.05)

cset=ax.contour(X,Y,Z,cmap=cm.coolwarm)

ax.clabel(cset,fontsize=9,inline=1)

plt.show()

二維的等高線,同樣可以配合三維表面圖一起繪制:

code:

frommpl_toolkits.mplot3dimportaxes3d

frommpl_toolkits.mplot3dimportaxes3d

importmatplotlib.pyplotasplt

frommatplotlibimportcm

fig=plt.figure()

ax=fig.gca(projection='3d')

X,Y,Z=axes3d.get_test_data(0.05)

ax.plot_surface(X,Y,Z,rstride=8,cstride=8,alpha=0.3)

cset=ax.contour(X,Y,Z,zdir='z',offset=-100,cmap=cm.coolwarm)

cset=ax.contour(X,Y,Z,zdir='x',offset=-40,cmap=cm.coolwarm)

cset=ax.contour(X,Y,Z,zdir='y',offset=40,cmap=cm.coolwarm)

ax.set_xlabel('X')

ax.set_xlim(-40,40)

ax.set_ylabel('Y')

ax.set_ylim(-40,40)

ax.set_zlabel('Z')

ax.set_zlim(-100,100)

plt.show()

也可以是三維等高線在二維平面的投影:

code:

frommpl_toolkits.mplot3dimportaxes3d

importmatplotlib.pyplotasplt

frommatplotlibimportcm

fig=plt.figure()

ax=fig.gca(projection='3d')

X,Y,Z=axes3d.get_test_data(0.05)

ax.plot_surface(X,Y,Z,rstride=8,cstride=8,alpha=0.3)

cset=ax.contourf(X,Y,Z,zdir='z',offset=-100,cmap=cm.coolwarm)

cset=ax.contourf(X,Y,Z,zdir='x',offset=-40,cmap=cm.coolwarm)

cset=ax.contourf(X,Y,Z,zdir='y',offset=40,cmap=cm.coolwarm)

ax.set_xlabel('X')

ax.set_xlim(-40,40)

ax.set_ylabel('Y')

ax.set_ylim(-40,40)

ax.set_zlabel('Z')

ax.set_zlim(-100,100)

plt.show()

八、Barplots(條形圖)

基本用法:

ax.bar(left,height,zs=0,zdir='z',*args,**kwargs

x,y,zs=z,數(shù)據(jù)zdir:條形圖平面化的方向,具體可以對應代碼理解。

code:

frommpl_toolkits.mplot3dimportAxes3D

importmatplotlib.pyplotasplt

importnumpyasnp

fig=plt.figure()

ax=fig.add_subplot(111,projection='3d')

forc,zinzip(['r','g','b','y'],[30,20,10,0]):

xs=np.arange(20)

ys=np.random.rand(20)

#Youcanprovideeitherasinglecolororanarray.Todemonstratethis,

#thefirstbarofeachsetwillbecoloredcyan.

cs=[c]*len(xs)

cs[0]='c'

ax.bar(xs,ys,zs=z,zdir='y',color=cs,alpha=0.8)

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

plt.show()

九、子圖繪制(subplot)

A-不同的2-D圖形,分布在3-D空間,其實就是投影空間不空,對應code:

frommpl_toolkits.mplot3dimportAxes3D

importnumpyasnp

importmatplotlib.pyplotasplt

fig=plt.figure()

ax=fig.gca(projection='3d')

#Plotasincurveusingthexandyaxes.

x=np.linspace(0,1,100)

y=np.sin(x*2*np.pi)/2+0.5

ax.plot(x,y,zs=0,zdir='z',label='curvein(x,y)')

#Plotscatterplotdata(202Dpointspercolour)onthexandzaxes.

colors=('r','g','b','k')

x=np.random.sample(20*len(colors))

y=np.random.sample(20*len(colors))

c_list=[]

forcincolors:

c_list.append([c]*20)

#Byusingzdir='y',theyvalueofthesepointsisfixedtothezsvalue0

#andthe(x,y)pointsareplottedonthexandzaxes.

ax.scatter(x,y,zs=0,zdir='y',c=c_list,label='pointsin(x,z)')

#Makelegend,setaxeslimitsandlabels

ax.legend()

ax.set_xlim(0,1)

ax.set_ylim(0,1)

ax.set_zlim(0,1)

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

B-子圖Subplot用法

與MATLAB不同的是,如果一個四子圖效果,如:

MATLAB:

subplot(2,2,1)

subplot(2,2,2)

subplo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論