通过ax.scatter3D()来使用Matplotlib的mplot3d工具包,创建一个3D散点图
示例1:
# Import libraries
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
# Creating dataset
z = np.random.randint(100, size=(300))
x = np.random.randint(80, size=(300))
y = np.random.randint(60, size=(300))
# Creating figure
fig = plt.figure(figsize=(10, 7))
ax = plt.axes(projection="3d")
# Creating plot
ax.scatter3D(x, y, z, color="green")
plt.title("simple 3D scatter plot")
# show plot
plt.show()
示例2:
# Import libraries
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
# Creating dataset
z = 4 * np.tan(np.random.randint(10, size =(500))) + np.random.randint(100,