English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Matplotlib 3D Plotting

D surface plot3Although Matplotlib was originally designed to consider only 2D plotting, in later versions, some 3D plotting utilities have been built on the 2D display of Matplotlib to provide a set of 3D data visualization tools. By importing the mplot

d package, you can enable 3D plotting.3By setting the keyword projection = '

d'Pass to any normal axis creation routine to create a 3D axis.

Example
# Filename: example.py 202# Copyright :30 By w
codebox3codebox.com
# Author by: www.w 2020-08-08
# Date : /#!/usr/bin
 env python-8
 #coding=utf-8
 import matplotlib.pyplot as plt
 import numpy as np
 import math
 import seaborn as sns-serif'] = ['SimHei']  # Step one (replacement of sans-serif font)
 Example code:3d
 fig = plt.figure()
 ax = plt.axes(projection='3d')
 z = np.linspace(0, 1, 100)
 x = z * np.sin(20 * z)
 y = z * np.cos(20 * z)
 ax.plot3D(x, y, z, 'gray')
 ax.set_title('3D line plot')
 plt.show()

plt.rcParams['axes.unicode_minus'] = False from mpl_toolkits import mplot -

Execute the above example code to get the following results3Now various types of 3D plots can be drawn. The most basic 3D plot is created based on the (x, y, z) triplet3D line plot. This can be done using ax.plot

Function D is created.3Use ax.scatter

Function D generates a 3D scatter plot.

Example
# Filename: example.py 202# Copyright :30 By w
codebox3codebox.com
# Author by: www.w 2020-08-08
# Date : /#!/usr/bin
 env python-8
 #coding=utf-8
 import matplotlib.pyplot as plt
 import numpy as np
 import math
 import seaborn as sns-serif'] = ['SimHei']  # Step one (replacement of sans-serif font)
 plt.rcParams['axes.unicode_minus'] = False  # Original text from [Lidihuo], commercial use please contact the author for authorization, non-commercial use please keep the original link:
 from mpl_toolkits import mplot3d
 fig = plt.figure()
 ax = plt.axes(projection='3d')
 z = np.linspace(0, 1, 100)
 x = z * np.sin(20 * z)
 y = z * np.cos(20 * z)
 ax.plot3D(x, y, z, 'gray')
 ax.set_title('3D line plot')
 plt.show()

Execute the above example code, and get the following results: