2016-03-24 19 views
2

私は、複数のサブプロットを含むmatplotlibウィンドウを持っています。メソッドが呼び出されるたびに、各サブプロットの内容を動的に更新できるようにしたい。簡略化されたコードは次のようになります:既に開いているMatplotlib図のサブプロットを更新する

import matplotlib.pyplot as plt 
import numpy as np 

fig = plt.figure(1) 
fig, ax_list = plt.subplots(3, 2) 

image1 = plt.imread("image1.jpg") 
image2 = plt.imread("image2.jpg") 
ax_list = ax_list.ravel() 
ax_list[0].imshow(image1) 
ax_list[1].imshow(image2) 
plt.show() 

def update_subplots(): 
    # I want this method to change the contents of the subplots whenever it is called 
    pass 
+1

あなたがいることを言うことを意味既に開いているウィンドウのサブプロットを更新したいですか? – ThePredator

+0

はい、それは正確に私が意味するものです – user3396592

+0

どのようにそれらを更新するのですか? – tom

答えて

0

私はこの方法を理解することができました。それは非常にきれいではありませんが、それは仕事を完了します。

我々はそうのようなグローバル変数に数値を設定することができます。

fig, ax_list = plt.subplots(4, 2) 

私たちはそのようになどのいずれかの方法からサブプロットの内容を変更することができます。

def update_subplot(image): 
    global fig, ax_list 
    ax_list = ax_list.ravel() 
    # ax_list[0] refers to the first subplot 
    ax_list[0].imshow(image) 
    plt.draw() 
関連する問題