所以我試圖創建一些隨時間推移的高斯圖的動畫。我的基本動畫也按我的意圖工作。但後來我想遮住高斯曲線下的區域。 我用ax.fill函數來遮擋它。但是,它只是陰影創建曲線的繪圖矢量,它只是變得一團糟。任何建議或幫助將不勝感激Python動畫陰影matplotlib
import numpy as np
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import matplotlib.animation as animation
import pylab as p
Gamma=0.0005
q=1.6e-19
m=0.067*9e-31
B=10
Ec=(1.0567e-34)*B/m
#e=2.78
#E0=0+(1.0567e-34)*x*i/m
fig, ax = plt.subplots()
n = 3 #number of lines
x = np.arange(0, 3.6e-3, 1.7e-5) # x-array, third number is interval here, x is energy
lines = [ax.plot(x, np.e**(-(x-((1.0567e-34)*1*1/m))**2/Gamma**2))[0]for _ in range(n)]
def animate(i):
for d, line in enumerate(lines):
p=(d+1)/2.
line.set_ydata(np.e**((-(x-((1.0567e-34)*p*i/m))**2)/Gamma**2))
ax.fill(x,(np.e**(-(x-((1.0567e-34)*p*i/m))**2/Gamma**2)), "b")# update the data
return lines
#Init only required for blitting to give a clean slate.
def init():
for line in lines:
line.set_ydata(np.ma.array(x, mask=True))
return lines
ani = animation.FuncAnimation(fig, animate, np.arange(0, 2.5, .01), init_func=init,
interval=10, blit=True)
Writer = animation.writers['ffmpeg']
writer = Writer(fps=20, metadata=dict(artist='Me'), bitrate=1800)
ani.save('QHanimati.mp4', writer=writer)
plt.show()
所以當前的代碼運行一個動畫,給出這樣的事情。 Curve
而且我想讓它離開白色曲線上方的區域。
謝謝。
嘗試增加'ax.clear()''之前ax.fill(...)''中的功能animate'。 – taras