Python绘制3D散点
程序员文章站
2022-04-02 10:04:30
...
# import necessary module
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import sys
# load data from file
# you can replace this using with open
data1 = np.loadtxt(str(sys.argv[1]))
tx = data1[:, 1]
ty = data1[:, 2]
tz = data1[:, 3]
# new a figure and set it into 3d
fig = plt.figure()
ax = fig.gca(projection='3d')
# set figure information
ax.set_title("Trajectory")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
# draw the figure, the color is r = read
figure = ax.scatter(tx, ty, tz, marker='.')
plt.show()
下一篇: 实现3d翻页