2014-03-25 3 views
0

스펙트럼 목록의 여러 버전을 비교해야하며 동일한 스펙트럼의 다른 버전을 표시 할 계획 인 각 스펙트럼에 대해 figure 개체를 생성하고 있습니다. 각 스펙트럼의 각 버전에는 동일한 페이지에 표시하려는 두 개의 "날개"가 있습니다. 그래서의 라인을 따라 뭔가를하려면 (파일 맞는에서 내가 NumPy와 배열로 스펙트럼을 나타내고, 나는 일반적으로 그들을 얻을) :matplotlib에서 이전에 생성 된 축으로 돌아 가기

다음
import os 
import sys 
import numpy as np 
import matplotlib.pyplot as mplt 
import matplotlib.gridspec as gs 
import numpy.random as rnd 

PageGrid = gs.GridSpec(11, 1, hspace = 0.0) 

Spec1 = rnd.randint(1, 100, 100) 
Spec2 = rnd.randint(1, 100, 100) 
Spec3 = rnd.randint(1, 100, 100) 

LeftSpecList = ['Spec1', 'Spec2', 'Spec3'] 

RightSpecList = ['Spec1', 'Spec2', 'Spec3'] 

for leftSpec in LeftSpecList: 
    fig = mplt.figure(str(leftSpec)) 
    axTop = fig.add_subplot(PageGrid[:5, :]) 
    axTop.plot(eval(leftSpec)) 


for rightSpec in RightSpecList: 
    fig = mplt.figure(str(rightSpec)) 
    axBottom = fig.add_subplot(PageGrid[6:, :])  
    axBottom.plot(eval(rightSpec)) 

내가 위에 플롯 할 스펙트럼의 두 번째 목록을 가지고 (또는 같은 아이폰에이 없을 수도 있습니다) 다른 사람 :

LeftSpecListNew = ['Spec1', 'Spec2'] 

RightSpecListNew = ['Spec2', 'Spec3'] 

for leftSpec in LeftSpecList: 
    fig = mplt.figure(str(leftSpec)) 
    axTop.plot(eval(leftSpec)) 


for rightSpec in RightSpecList: 
    fig = mplt.figure(str(rightSpec)) 
    axBottom.plot(eval(leftSpec)) 

mplt.show() 

하지만 나는 그것이 첫 번째 그림에 모든 인쇄, 그렇게 할 때. 어떤 아이디어?

답변

1

axTop 및 axBottom은 처음 두 루프에서 덮어 씁니다. 각 그림의 상단 및 하단 축을 추적해야합니다. 이 같은 것은 당신이 원하는 것을해야합니다.

axTopDict = {} 
for leftSpec in LeftSpecList: 
    fig = mplt.figure(str(leftSpec)) 
    axTop = fig.add_subplot(PageGrid[:5, :]) 
    axTop.plot(eval(leftSpec),'ro') 
    axTopDict[leftSpec] = axTop # associate this axis with this figure name 

axBottomDict = {} 
for rightSpec in RightSpecList: 
    fig = mplt.figure(str(rightSpec)) 
    axBottom = fig.add_subplot(PageGrid[6:, :])  
    axBottom.plot(eval(rightSpec),'b*') 
    axBottomDict[rightSpec] = axBottom # associate this axis with this figure name 

LeftSpecListNew = ['Spec1', 'Spec2'] 

RightSpecListNew = ['Spec2', 'Spec3'] 

for leftSpec in LeftSpecList: 
    fig = mplt.figure(str(leftSpec)) 
    axTop = axTopDict[leftSpec] # get the top axis associated with this figure name 
    axTop.plot(eval(leftSpec),'m') 


for rightSpec in RightSpecList: 
    fig = mplt.figure(str(rightSpec)) 
    axBottom = axBottomDict[rightSpec] # get the bottom axis associated with this figure name 
    axBottom.plot(eval(leftSpec),'g') 

mplt.show() 
+0

감사합니다. – jorgehumberto