ループ中に更新したい複数の図を含む python スクリプトがあります。一部は画像で、その他は線/散布図になります。画像を正しい図に表示するのに問題があります。(線と散布図のデータは右の Figure に表示されていますが、イメージは常に最後に作成された Figure に表示されているようです。最終的には複数のイメージ Figure を表示することになるため、イメージ図ラスト)
これは私がこれまでに持っていた大まかなコードです。図 1 には 3D 散布図が表示されていますが、図 3 には画像と折れ線グラフの両方が表示されており、図 2 は空白になっています。
import matplotlib.pyplot as plt
from collections import deque
class Bla():
  def __init__( self ):
    self.pc_fig = plt.figure(1)
    self.pc_ax = self.pc_fig.add_subplot(111, projection='3d')
    self.pc_ax.set_xlim3d([0, 50])
    self.pc_ax.set_ylim3d([0, 50])
    self.pc_ax.set_zlim3d([0, 20])
    self.pc_ax.hold(False)
    self.vts_fig = plt.figure(2)
    self.vts_ax = self.vts_fig.add_subplot(111)
    self.em_fig = plt.figure(3)
    self.em_ax = self.em_fig.add_subplot(111)
    self.em_ax.hold(True)
    self.image_data = deque()
    self.motion_data = deque()
    plt.ion()
    plt.show()
  def run( self ):
    em_prev_xy = ( 0, 0 )
    while True:
      if len( self.motion_data ) > 0:
        data1 = self.motion_data.popleft()
        em_xy = data1.get_em()
        self.em_ax.plot( [ em_prev_xy[0], em_xy[0] ], [ em_prev_xy[1], em_xy[1] ],'b')
        pc = self.get_pc()
        pc_index = nonzero(pc>.002)
        pc_value = pc[pc_index] * 100
        self.pc_ax.scatter(pc_index[0],pc_index[1],pc_index[2],s=pc_value)
        self.pc_ax.set_xlim3d([0, 50])
        self.pc_ax.set_ylim3d([0, 50])
        self.pc_ax.set_zlim3d([0, 20])
        plt.pause( 0.0001 ) # This is needed for the display to update
      if len( self.image_data ) > 0:
        im = self.image_data.popleft()
        plt.imshow( im, cmap=plt.cm.gray, axes=self.vts_ax )
        plt.pause( 0.0001 )
def main():
  bla = Bla()
  bla.run()
if __name__ == "__main__":
  main()
基本的に、新しいデータが到着したときにコールバックで入力されるいくつかのキューがあり、このデータが到着すると表示されるようにします。
私はmatplotlibを初めて使用するので、画像表示の問題に関するヘルプや、matplotlibを使用して一般的に図を表示するためのより良い方法のヒントをいただければ幸いです