matplotlib绘制三维散点图 作者:马育民 • 2019-08-07 16:10 • 阅读:10111 [![](https://www.malaoshi.top/upload/0/0/1EF3x8ddKWSM.png)](https://www.malaoshi.top/upload/0/0/1EF3x8ddKWSM.png) ``` from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(15,6),dpi=100) ax = fig.add_subplot(111, projection='3d') x=np.array([[-30, -20, -10, 0, 10, 20,], [-30, -20, -10, 0, 10, 20,], [-30, -20, -10, 0, 10, 20,], [-30, -20, -10, 0, 10, 20,], [-30, -20, -10, 0, 10, 20,], [-30, -20, -10, 0, 10, 20,]]) y=np.array([[-30, -30, -30, -30, -30, -30,], [-20, -20, -20, -20, -20, -20,], [-10, -10, -10, -10, -10, -10,], [ 0, 0, 0, 0, 0, 0,], [ 10, 10, 10, 10, 10, 10,], [ 20, 20, 20, 20, 20, 20,]]) z=np.array([[ 0, 1, 2, 3, 4, 5], [ 0, 1, 2, 3, 4, 5], [ 0, 1, 2, 3, 4, 5], [ 0, 1, 2, 3, 4, 5], [ 0, 1, 2, 3, 4, 5], [ 0, 1, 2, 3, 4, 5]]) z=x*0.2+y*0.8+10 z2=np.random.normal(loc=z, scale=10, size=(6,6)) ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') ax.view_init(elev=30,azim=-25) ax.scatter(x, y, z2,color='red') plt.show() ``` 原文出处:http://malaoshi.top/show_1EF3q1v3nSSk.html