Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matplotlib python中删除previus散点_Python_Matplotlib - Fatal编程技术网

如何在matplotlib python中删除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,

在我的代码中,我想使用动画功能在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,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()