Home > Backend Development > Python Tutorial > Can python draw 3D pictures?

Can python draw 3D pictures?

爱喝马黛茶的安东尼
Release: 2019-06-19 09:29:48
Original
4293 people have browsed it

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

Can python draw 3D pictures?

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: windows From the command line, go to the Scripts folder in the python installation directory and execute: pip install --upgrade matplotlib; execute this command directly in the Linux environment.

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

Related recommendations: "python video tutorial"

The following takes the drawing process of a sphere as an example

1. 3D Drawing of surface shape

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
  
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
  
# Make data
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
  
# Plot the surface
ax.plot_surface(x, y, z, color='b')
  
plt.show()
Copy after login

Spherical surface, the results are as follows:

Can python draw 3D pictures?

The above is the detailed content of Can python draw 3D pictures?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template