欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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()