Home >Backend Development >Python Tutorial >Python uses matplotlib to draw 3D graphics (code example)

Python uses matplotlib to draw 3D graphics (code example)

不言
不言forward
2019-04-12 11:38:444304browse

The content of this article is about using matplotlib to draw 3D graphics (code examples) in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

3D graphics are widely used in the fields of data analysis, data modeling, graphics and image processing. The following will introduce to you how to use matplotlib in Python to draw 3D graphics, including 3D scatter. Drawing of points, 3D surfaces, 3D contours, 3D straight lines (curves) and 3D text, etc.

Preparation work:

To draw 3D graphics in python, you still use the commonly used drawing module matplotlib, but you need to install the mpl_toolkits toolkit. The installation method is as follows: enter the python installation directory from the windows command line In the Scripts folder, execute: pip install --upgrade matplotlib; execute this command directly in Linux environment.

After installing this module, you can call the mplot3d class under mpl_tookits to draw 3D graphics.

The following is an example.

1. Drawing of 3D surface shape


This code draws a 3D ellipsoid surface. The result is as follows:

2. Drawing of 3D straight lines (curves)


This code is used to draw a spiral 3D curve, the results are as follows:

3. Draw 3D contour


The drawing results are as follows :

4. Draw a 3D histogram

##The drawing results are as follows:


5. Draw 3D mesh lines



##The drawing results are as follows:

6. Draw 3D triangle patch diagram


##The drawing results are as follows:


7. Draw a 3D scatter plot


The drawing results are as follows:



The above is the detailed content of Python uses matplotlib to draw 3D graphics (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete