Tbe*_*bee 6 animation matplotlib title colorbar
我在matplotlib做了一个动画.您可以在下面找到我的代码的简化:
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
begin = 62
eind = 227
verschil = eind - begin
fig = plt.figure()
def f(x, y):
return np.sin(x) + (0*y)
x = np.linspace(0, 2 * np.pi, 501)
y = np.linspace(0, 2 * np.pi, 501).reshape(-1, 1)
afbeeldinglijst = []
for i in range(verschil):
x = x + 1
titel = begin + 1
afbeelding = plt.imshow(f(x, y))
afbeeldinglijst.append([afbeelding])
plt.colorbar()
plt.title(titel)
plt.clim(-0.8,0.8)
A = animation.ArtistAnimation(fig, afbeeldinglijst, interval=verschil, blit=True, repeat_delay=2000)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我的问题是我能看到的唯一的东西是颜色条.而不是改变每一帧的颜色条,它只是为图形添加了颜色条.我希望我的颜色条随着图片中的每一个变化而变化.同样的标题,我想为图像中的每个变化一个新的标题,从62到227.我怎么能这样做?我希望我能清楚自己想要的东西:).谢谢!
如果有人感兴趣,我自己修理了它:现在我在动画中有一个文本,它给出了62到227之间的正确数字.我还将颜色条固定为每帧的正确数字.我刚刚为plt.imshow添加了最小值和最大值,因此所有帧都具有相同的最小值和最大值; 然后我添加了一个颜色条.在我的代码下面(因为我使用它,而不是如上所述的简化版本):
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
begin = 62
eind = 227
minwaarde = 0
maxwaarde = 0.05
verschil = eind - begin
fig = plt.figure()
ax = fig.add_subplot(111)
def f(x, y):
return np.genfromtxt("../e/c"+str(begin)+".txt",delimiter="") + (0*y)
x = np.arange(0, 501)
y = np.arange(0, 501).reshape(-1,1)
afbeeldinglijst = []
for i in range(verschil):
t = ax.annotate(begin,(50,50),color='w')
begin = begin + 1
afbeelding = plt.imshow(f(x, y),vmin=minwaarde,vmax=maxwaarde)
afbeeldinglijst.append([afbeelding,t])
A = animation.ArtistAnimation(fig, afbeeldinglijst, interval=verschil, blit=True, repeat_delay=2000)
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1959 次 |
| 最近记录: |