作者WalterbyJeff (Spark Of Insanity)
看板Python
标题[问题] show lines then remove it
时间Mon Jul 16 00:07:21 2012
Is there anyone knows how to remove a line just after it showed up?
I dynamically generate a bunch of dots via this
ax.plot([x,0],[y,0],[z,0],color='#817339',marker='.')
#x,y,z being continously updated
So, I'll get a lot of lines from (0, 0, 0) to (x, y, z)
now the question is:
How do I remove those outdated lines?
Or the whole 3D graph would be kind of messy after a while---
so many lines on the screen.
thanks!
PS. As for removing axis, it's pretty easy, just
ax.axis("off")
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.36.28.49
※ 编辑: WalterbyJeff 来自: 114.36.28.49 (07/16 00:13)
1F:→ KSJ:just google 'matplotlib delete line' 07/16 10:20
我之前有试过这两个指令
del ax.lines[0]
ax.lines.pop(0)
但是我发觉我产生线段的那条必须要打两次,才不会一开始根本不会显示出来
我猜原因是时间太短,马上生出来又马上给拿掉了,所以没显示
而且就算用打两次还有其他问题,打两次产生线段的指令
line = ax.plot([x,0],[y,0],[z,0],color='#0000A0',marker='.')
line = ax.plot([x,0],[y,0],[z,0],color='#0000A0',marker='.')
ax.lines.pop(0)
会让图形跑到愈後面没消掉的线愈多,就像滑鼠设定延迟有一堆残影游标一样
※ 编辑: WalterbyJeff 来自: 114.36.40.153 (07/17 22:30)
2F:→ KSJ:可以给个小小的概念程式码让我跑看看吗 感恩 07/17 22:54
#我把原来计算出新的位置向量 n 的演算法简化
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from numpy import *
from pylab import *
import pylab
class vec(object):
def __init__(self, x, y, z):
self.vec=(x, y, z)
def unit(self, vec):
dist=math.sqrt(vec[0]**2+vec[1]**2+vec[2]**2)
u=(vec[0]/dist,vec[1]/dist,vec[2]/dist)
return u
def plotlines(x ,y ,z):
line = ax.plot([x,0],[y,0],[z,0],color='#0000A0',marker='.')
#生产"线"的指令
ax.lines.pop(0)
#删除线的指令
#如果加上这条,3D影像的图还是会跑(背景的尺寸一直在变)
但是线看不到,如果生产线的指令加两条,就看得到,很美好的
跑一个删一个,但跑一小段时间之後,延迟没删掉的线就会愈来愈多
我甚至还很疯狂的把生产线的指令弄成k个,删除的弄成k-1个
这种显示一个删一个的状况就能拖久一点,但是最後还是...
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
#del ax.lines[0]
#这条我先注解掉,状况也跟上面一样
matplotlib.pyplot.show()
def drawdynamicplot(m,n,d_n):
for i in range(0,m):
#n=vector.rungekutta1(n, d_n)
#d_n=vector.rungekutta2(n, d_n)
x1 = sin(n[0] - .5*i)
y1 = cos(n[1]+.1*i)
z1 = sin(n[2] - i**3)
n= (x1,y1,z1)
n=vector.unit(n)
print n
if i%25 == 0:
print "-----------------------------"
plotlines(n[0],n[1],n[2])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
vector=vec(1,2,3)
n=(1.0,1.0,1.0)
d_n=(1.0,-1.0,0.0)
ion()
m=10000
xarray=[]
yarray=[]
zarray=[]
drawdynamicplot(m,n, d_n)
---
先谢谢了~~
※ 编辑: WalterbyJeff 来自: 114.36.40.153 (07/17 23:57)
3F:→ KSJ:一直show不行 强迫要先画请用draw 07/19 17:04
4F:→ KSJ:还有如果画两次线段 也要移掉二条线段啊~ 不移一定多一条 07/19 17:28
5F:→ KSJ:对了 如果可以的话 下次贴长code 可以贴连结 07/19 17:30
7F:→ WalterbyJeff:谢了~ 完整的程式码(不过我数学模型还在修改) 07/19 17:35