Python繪製散點圖(2D/3D)

3D散點圖

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

2D散點圖

# 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]

# new a figure
fig = plt.figure()
ax = fig.gca()

# set figure information
ax.set_title("Pixels")
ax.set_xlabel("x")
ax.set_ylabel("y")

# draw the figure, the color is r = read
figure = ax.scatter(tx, ty, marker='.')

plt.show()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章