Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Surface plots and Contour plots in Python
Next article icon

ATri-Surface Plot is a type of surface plot, created by triangulation of compact surfaces of finite number of triangles which cover the whole surface in a manner that each and every point on the surface is in triangle. The intersection of any two triangles results in void or a common edge or vertex. This type of plot is created where the evenly sampled grids are restrictive and inconvenient to plot. Generally Tri-Surface plots are created by calling ax.plot_trisurf() function ofmatplotlib library. Some of the attributes of the function are listed below:

AttributeParameter
X, Y, Zdataset as 1D array to be plotted
colorscolor of the surface patches
cmapcolor map to set the color of surface patches
normparameter to normalize map values of colors
vminminimum value of map
vamxmaximum value of map
shadeattribute to shade the facecolors

Example 1:Let's create a basic Tri-Surface plot using the ax.plot_trisurf() function. 

Python3
# Import librariesfrommpl_toolkitsimportmplot3dimportnumpyasnpimportmatplotlib.pyplotasplt# Creating datasetz=np.linspace(0,50000,100)x=np.sin(z)y=np.cos(z)# Creating figurefig=plt.figure(figsize=(14,9))ax=plt.axes(projection='3d')# Creating plotax.plot_trisurf(x,y,z,linewidth=0.2,antialiased=True);# show plotplt.show()

Output : 

Tri-Surface Plot in Python using Matplotlib

Example 2 :For better understanding Let's take another example. 

Python3
# Import librariesfrommpl_toolkits.mplot3dimportAxes3Dimportmatplotlib.pyplotaspltimportnumpyasnp# Creating radii and anglesr=np.linspace(0.125,1.0,100)a=np.linspace(0,2*np.pi,100,endpoint=False)# Repeating all angles for every radiusa=np.repeat(a[...,np.newaxis],100,axis=1)# Creating datasetx=np.append(0,(r*np.cos(a)))y=np.append(0,(r*np.sin(a)))z=(np.sin(x**4)+np.cos(y**4))# Creating figurefig=plt.figure(figsize=(16,9))ax=plt.axes(projection='3d')# Creating color mapmy_cmap=plt.get_cmap('hot')# Creating plottrisurf=ax.plot_trisurf(x,y,z,cmap=my_cmap,linewidth=0.2,antialiased=True,edgecolor='grey')fig.colorbar(trisurf,ax=ax,shrink=0.5,aspect=5)ax.set_title('Tri-Surface plot')# Adding labelsax.set_xlabel('X-axis',fontweight='bold')ax.set_ylabel('Y-axis',fontweight='bold')ax.set_zlabel('Z-axis',fontweight='bold')# show plotplt.show()

Output: 

Tri-Surface Plot in Python using Matplotlib


 


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp