[問題] show lines then remove it
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)
→
07/16 10:20, , 1F
07/16 10:20, 1F
我之前有試過這兩個指令
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)
→
07/17 22:54, , 2F
07/17 22:54, 2F
#我把原來計算出新的位置向量 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)
→
07/19 17:04, , 3F
07/19 17:04, 3F
→
07/19 17:28, , 4F
07/19 17:28, 4F
→
07/19 17:30, , 5F
07/19 17:30, 5F
→
07/19 17:31, , 6F
07/19 17:31, 6F
→
07/19 17:35, , 7F
07/19 17:35, 7F
→
07/19 17:35, , 8F
07/19 17:35, 8F