如何在matplotlib python中删除previus散点
在我的代码中,我想使用动画功能在3d图形上绘制运动点,但当它绘制新点时,它不会擦除previus点。我的代码如下所示如何在matplotlib python中删除previus散点,python,matplotlib,Python,Matplotlib,在我的代码中,我想使用动画功能在3d图形上绘制运动点,但当它绘制新点时,它不会擦除previus点。我的代码如下所示 from mpl_toolkits.mplot3d import Axes3D from matplotlib import animation import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x =[1,2,3,4,5,6,7,8,
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x =[1,2,3,4,5,6,7,8,9,10]
y =[5,6,2,3,13,4,1,2,4,8]
z =[2,3,3,3,5,7,9,11,9,10]
#ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
def draw_graph(i):
for i in range(len(x)):
x[i]+=1
ax.scatter(x, y, z, c='r', marker='o')
anima = animation.FuncAnimation(plt.gcf(),draw_graph,interval=1000)
plt.show()
只需在ax.scatter(x,y,z,c='r',marker='o')
行之前调用ax.clear()