基本的に私がやりたいことは、複数のプロセス間で共有されているデータを更新/アニメーション化するグラフをリアルタイムで描画することです。私は python multiprocessing モジュールの Manager を使用し、 while ループwave
内の別のプロセスで更新/変更されたリスト (配列) を共有しました。
FuncAnimation 関数を実行すると、同じプロセス内のローカル変数またはグローバル変数に従って表示されるデータしか更新できないようです。これが私のコードです:
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
x = np.arange(0, 4408)
wave = np.arange(0, 4408)
def animate(i):
plt.cla()
global x
x = [a + 4408 for a in x] # x-axis continues to shift
plt.plot(x, wave)
# wave array from another process
def graph(shared_wave):
global wave
wave = shared_wave # Here it gets updated once but never again
ani = FuncAnimation(plt.gcf(), animate, interval=100)
plt.tight_layout()
plt.show()
どんな助けでも大歓迎です。私が考えていることの 1 つは、あるプロセスでマルチスレッドを使用してアニメーションを 1 つのスレッドで実行し、別のスレッドでグローバル変数を更新することです。