我有一段代码:
fig,ax=subplots(figsize=(20,10))
#ax=plot(matriz[0],matriz[1],color='black',lw=0,marker='+',markersize=10)
#ax=plot(matriz[2],matriz[3],color='blue',lw=0,marker='o',markersize=10)
#show ()
def animate(i):
ax=plot((matt[i][0],matt[i][2]),(matt[i][1],matt[i][3]),lw=0,color='r-',marker='o',markersize=8)
return ax
anim=animation.FuncAnimation(fig,animate,frames=numlin, interval=1000,blit=True,repeat=0)
show()
我真的没有matplotlib的经验,但是我的老板让我(在每次迭代中)用不同的颜色绘制每个点(即点1用红色,点2用蓝色等等)。我想用不同的颜色绘制每个点,但是在下一次迭代中应该保持相同的颜色。在
如何在matplotlib中执行此操作?在
我想我知道你想做什么,是的,我认为这是可能的。首先,我设置了一些随机数据来模拟
matt
中的内容现在,尽可能地使用代码,我想您应该这样做(我添加了一个
^{2}$init()
函数,它只返回一个空列表,否则您的第一组点始终保持在轴上):工作原理
将
(x0,y0,c0, x1,y1,c1, x2,y2,c2 ... )
集传入plot()
是有效的,其中cx
是有效的matplotlib颜色格式。它们位于任何名为**kwargs
的前面,如marker
等It's described in the docs here。在编辑回应OP评论
OP想让这个扩展到更多的点集,而不是简单地将它们作为参数附加到plot函数中。这里有一种方法(改变
animate()
函数-其余的保持不变)相关问题 更多 >
编程相关推荐