0
我在教自己的python數學動畫,所以我甚至不知道我問的是否可以用matplotlib。我想要的是 (1)的軸開始小,然後展開。在此之後,我想要它 (2)順序(一個接一個地)繪製兩行,而不是同時(在同一時間),它正在做什麼。
我的代碼如下,除了我嘗試擴展軸(最好我的嘗試沒有崩潰蟒蛇)。在python和matplotlib中動畫軸的大小和2個連續的動畫
import time
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
#from matplotlib.animation import FuncAnimation
maxsize = 8
size = 1
fig = plt.figure(figsize=(maxsize, maxsize))
# fig will start at "size" if I ever figure out the animation
xmin = -10
xmax = 10
ymin = -10
ymax = 10
ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax))
plt.axhline(linewidth=3, color='black')
plt.axvline(linewidth=3, color='black')
line, = ax.plot([], [], lw=2)
def init1():
line.set_data([], [])
return line,
def animate1(i):
x1 = np.linspace(-10, i/5 - 10, 1000)
y1 = -1*x1
line.set_data(x1, y1)
return line,
def init2():
line.set_data([], [])
return line,
def animate2(j):
x2 = np.linspace(0, j/10, 1000)
y2 = 2*x2
line.set_data(x2, y2)
return line,
plt.grid()
plt.xticks(np.arange(xmin, xmax+1, 1.0))
plt.yticks(np.arange(ymin, ymax+1, 1.0))
anim1 = animation.FuncAnimation(fig, animate1, init_func=init1,
frames=100, interval=20, blit=True)
plt.plot()
plt.show()
time.sleep(1)
anim2 = animation.FuncAnimation(fig, animate2, init_func=init2,
frames=100, interval=20, blit=True)
plt.plot()
plt.show()
所以我想我的問題是: 是我想在matplotlib做可能嗎?一?另一個?都? 如果是這樣,我該怎麼做。
尺寸限制下我不清楚你想要什麼;讓我們試着澄清一下:'(1)軸從小到大,然後展開「,這是數字線上的某種縮放效果? (2)按順序繪製兩行而不是同時繪製你想繪製一條線,然後在另一條線上繪製(保留第一行)?或者你想顯示一個情節與第一個,然後另一個與第二個? –
(1)我想讓軸開始小,讓我們說1「1」,然後長到8「8」。 (2)我想在一個繪圖上畫一條線,暫停,然後在同一個繪圖上繪製第二條線。 – SaintCad