下面的編碼是我的代碼。我想在列印所有資料和每個資料的標記后標記軸。我不知道為什么標簽名稱只顯示在開頭。
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
np.set_printoptions(threshold=np.inf)
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
def init():
global points
points = np.loadtxt('Surface.txt')
def animate(i):
ax1.clear()
ax1.plot(points[:i, 0], points[:i, 1], points[:i, 2])
ani = animation.FuncAnimation(fig, animate, init_func=init, interval = 1000)
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
plt.show()
Surface.txt 的內容是
0 0 3
1 1 4
2 4 8
4 16 6
5 25 5
6 36 3
uj5u.com熱心網友回復:
您還可以通過set_label在def animate()函式中添加這樣的命令來實作
def animate(i):
ax1.clear()
ax1.plot(points[:i, 0], points[:i, 1], points[:i, 2])
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
所以最終的程式將如下所示:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
np.set_printoptions(threshold=np.inf)
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
def init():
global points
points = np.loadtxt('Surface.txt')
def animate(i):
ax1.clear()
ax1.plot(points[:i, 0], points[:i, 1], points[:i, 2])
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
ani = animation.FuncAnimation(fig, animate, init_func=init, interval = 1000)
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_zlabel('z')
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/345397.html
標籤:Python matplotlib
