Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Tri-Surface Plot in Python using Matplotlib
Next article icon
Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing themplot3d toolkit. Let's look at a 3d contour diagram of a 3d cosine function. The code is attached for reference.
Function ArgumentsDescription
meshgridFunction of numpy used to create a rectangular grid out of two given one-dimensional arrays representing the Cartesian indexing or Matrix indexing
plt.axes()To create object of the axis
ax.contour3DTo form the contour
ax.set_xlabelTo label the X-axis
ax.set_titleTo give a title to the plot
Example 1:Python3
frommpl_toolkitsimportmplot3dimportnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlibimportcmimportmathx=[iforiinrange(0,200,100)]y=[iforiinrange(0,200,100)]X,Y=np.meshgrid(x,y)Z=[]foriinx:t=[]forjiny:t.append(math.cos(math.sqrt(i*2+j*2)))Z.append(t)fig=plt.figure()ax=plt.axes(projection='3d')ax.contour3D(X,Y,Z,50,cmap=cm.cool)ax.set_xlabel('a')ax.set_ylabel('b')ax.set_zlabel('c')ax.set_title('3D contour for cosine')plt.show()
Output:3D Contour Plotting Example 2: Let's look at another 3d diagram for better understanding of the concept. This time, of a 3d tan function.Python3
frommpl_toolkitsimportmplot3dimportnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlibimportcmimportmathx=[iforiinrange(0,200,100)]y=[iforiinrange(0,200,100)]X,Y=np.meshgrid(x,y)Z=[]foriinx:t=[]forjiny:t.append(math.tan(math.sqrt(i*2+j*2)))Z.append(t)fig=plt.figure()ax=plt.axes(projection='3d')ax.contour3D(X,Y,Z,50,cmap=cm.cool)ax.set_xlabel('a')ax.set_ylabel('b')ax.set_zlabel('c')ax.set_title('3D contour for tan')plt.show()
Output:3D Contour Plotting

Improve
Practice Tags :

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