下のコードからアニメーションヒストグラムを作成しようとしています。私は毎回個別のヒストグラムを作成することができますが、matplotlib.animation
関数を使ってアニメートするか、matplotlib tutorialのコードをエミュレートすることはできません。Matplotlibアニメーションヒストグラム
import numpy as np
import matplotlib.pyplot as plt
betas = [] # some very long list
entropy = [] # some very long list
for time in [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0 , 3.5, 4.0, 4.5 5.0, 5.5, 6.0, 6.5 , 7.0, 7.5, 8.0 , 8,5 , 9.0, 9.5 , 10.0]:
plt.figure('entropy distribution at time %s ' % time)
indexbetas = {i for i, j in enumerate(betas) if j == time}
desiredentropies = [x for i, x in enumerate(entropy) if i in indexbetas] #the desiredentropies list depends on time
n, bins, patches = plt.hist(desiredentropies, 20, alpha=0.75 , label = 'desired entropies')
plt.xlabel(r"$S_{(\time=%d)}$" % time, fontsize=20)
plt.ylabel('Frequency of entropies')
plt.legend()
plt.grid(True)
plt.show()
私はアニメーションのtime
リストの要素に依存して私のdesiredentropies
リストを供給するとともに、特に苦労しています。
チュートリアルの例は、Python 2.7.11と3.4.3/Linux Mintで動作するには数秒必要です。console/terminal/cmd.exeにエラーメッセージが表示されますか? – furas
@furas OPに編集を追加しました。私の主な問題は、時間の変化に応じて、ヒストグラムを作成したい、更新されたdesiredentropiesリストを与えることです。注:必要なエントロピーリストは、各要素の時間変化を示します。 –
'animation.FuncAnimation'を使用する必要があります – furas