matplotlibでアニメーションを作成して、複数のデータセットを1つのアニメーションに同時にプロットしようとしています。 問題は、自分のデータセットのうち2つに50ポイント、3番目に70000ポイントがあることです。したがって、第1の2つのデータセットは、第3のデータセットが表示され始めたばかりのときにプロットされるので、(ポイント間で同じ間隔で)同時のプロットは役に立たない。python matplotlib複数行アニメーション
したがって、データセットを別々のアニメーション呼び出し(異なる間隔、つまり描画速度)でプロットするようにしようとしていますが、1つのプロットで行います。問題は、最後に呼び出されたデータセットに対してのみアニメーションが表示されることです。
の下にランダムなデータのためのコードを参照してください:最後のプロットは次のようになります。
import numpy as np
from matplotlib.pyplot import *
import matplotlib.animation as animation
import random
dataA = np.random.uniform(0.0001, 0.20, 70000)
dataB = np.random.uniform(0.90, 1.0, 50)
dataC = np.random.uniform(0.10, 0.30, 50)
fig, ax1 = subplots(figsize=(7,5))
# setting the axes
x1 = np.arange(0, len(dataA), 1)
ax1.set_ylabel('Percentage %')
for tl in ax1.get_xticklabels():
tl.set_color('b')
ax2 = ax1.twiny()
x2 = np.arange(0, len(dataC), 1)
for tl in ax2.get_xticklabels():
tl.set_color('r')
ax3 = ax1.twiny()
x3 = np.arange(0, len(dataB), 1)
for tl in ax3.get_xticklabels():
tl.set_color('g')
# set plots
line1, =ax1.plot(x1,dataA, 'b-', label="dataA")
line2, =ax2.plot(x2,dataC, 'r-',label="dataB")
line3, =ax3.plot(x3, dataB, 'g-', label="dataC")
# set legends
ax1.legend([line1, line2, line3], [line1.get_label(),line2.get_label(), line3.get_label()])
def update(num, x, y, line):
line.set_data(x[:num], y[:num])
line.axes.axis([0, len(y), 0, 1]) #[xmin, xmax, ymin, ymax]
return line,
ani = animation.FuncAnimation(fig, update, len(x1), fargs=[x3, dataB, line3],interval=150, blit=True, repeat=False)
ani = animation.FuncAnimation(fig, update, len(x1), fargs=[x1, dataA, line1],interval=5, blit=True, repeat=False)
ani = animation.FuncAnimation(fig, update, len(x1), fargs=[x2, dataC, line2],interval=150, blit=True, repeat=False)
# if the first two 'ani' are commented out, it live plots the last one, while the other two are plotted static
show()
: http://i.imgur.com/RjgVYxr.png
しかし、ポイントは同時にアニメーションを取得することです(ただし、異なるペースで)線を引く。
ありがとうございました!できます! – MVab