Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/
matplotlib

Navigation


Travis-CI:

Related Topics

This Page

Quick search

mplot3d example code: surface3d_demo3.py

(Source code,png,pdf)

../../_images/surface3d_demo3.png
'''=========================3D surface (checkerboard)=========================Demonstrates plotting a 3D surface colored in a checkerboard pattern.'''frommpl_toolkits.mplot3dimportAxes3Dimportmatplotlib.pyplotaspltfrommatplotlibimportcmfrommatplotlib.tickerimportLinearLocatorimportnumpyasnpfig=plt.figure()ax=fig.gca(projection='3d')# Make data.X=np.arange(-5,5,0.25)xlen=len(X)Y=np.arange(-5,5,0.25)ylen=len(Y)X,Y=np.meshgrid(X,Y)R=np.sqrt(X**2+Y**2)Z=np.sin(R)# Create an empty array of strings with the same shape as the meshgrid, and# populate it with two colors in a checkerboard pattern.colortuple=('y','b')colors=np.empty(X.shape,dtype=str)foryinrange(ylen):forxinrange(xlen):colors[x,y]=colortuple[(x+y)%len(colortuple)]# Plot the surface with face colors taken from the array we made.surf=ax.plot_surface(X,Y,Z,facecolors=colors,linewidth=0)# Customize the z axis.ax.set_zlim(-1,1)ax.w_zaxis.set_major_locator(LinearLocator(6))plt.show()

Keywords: python, matplotlib, pylab, example, codex (seeSearch examples)

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp