2013-05-24 3 views
1

기본적으로 gridspec과 APLpy를 결합하려고합니다.APLpy와 matplotlib와의 비 호환성 gridspec

하지만 어쨌든 서브 플로트의 행에서 첫 번째 음모는 항상 작동합니다. 즉, 음원의 크기가 예상 한 것과 다릅니다. 첫 번째 이미지는 다소 큰 프레임을 보여 주지만 다른 이미지는 정사각형입니다.

나는 기본적으로 재조정 또는 첫 번째 플롯의 크기를 조정하는 내가 생각할 수있는 모든 것을 시도했다

수동으로 전 APLpy로 충전 후 transformsBbox를 사용하여 크기를 설정

  • get_position().bounds을 요구하지 않음 하지만 단순히 get_position() 이전과 부가 적 줄거리
를 작성 후 set_aspect('equal')를 사용하여 APLpy 명령
  • 에서

    아무것도 작동하지 않습니다. 그것은 이미지와 관련이 없으며, 다른 이미지를 그렸거나 동일한 결과로 주문 결과를 변경합니다.

    간단히 말해 첫 번째 서브 플로트의 크기를 변경하지 못하게 할 수 있습니다. gridspec 주변의 방법은 없습니다. 서브 플로트의이 시리즈는 더 큰 플롯의 일부이고 gridspec 이외의 다른 것을 사용하면 모든 것을 복잡하게 만들 것이기 ​​때문입니다.

    도움이된다면 크게 환영 할 것입니다.

    import matplotlib 
    matplotlib.use('Agg') 
    import matplotlib.pyplot as plt 
    from matplotlib import gridspec 
    import aplpy 
    
    f=plt.figure() 
    gs=gridspec.GridSpec(1,4) 
    ax0=plt.subplot(gs[0,0]);ax1=plt.subplot(gs[0,1]);ax2=plt.subplot(gs[0,2]);ax3=plt.subplot(gs[0,3]) 
    ax0.set_aspect('equal'); ax1.set_aspect('equal'); ax2.set_aspect('equal'); ax3.set_aspect('equal'); 
    ax0.axes.get_xaxis().set_ticks([]); ax1.axes.get_xaxis().set_ticks([]); ax2.axes.get_xaxis().set_ticks([]); ax3.axes.get_xaxis().set_ticks([]) 
    ax0.axes.get_yaxis().set_ticks([]); ax1.axes.get_yaxis().set_ticks([]); ax2.axes.get_yaxis().set_ticks([]); ax3.axes.get_yaxis().set_ticks([]) 
    
    fig0=aplpy.FITSFigure(img0, figure=f, subplot=ax0.get_position().bounds); fig0.show_grayscale(invert=True) 
    fig1=aplpy.FITSFigure(img1, figure=f, subplot=ax1.get_position().bounds); fig1.show_grayscale(invert=True) 
    fig2=aplpy.FITSFigure(img2, figure=f, subplot=ax2.get_position().bounds); fig2.show_grayscale(invert=True) 
    fig3=aplpy.FITSFigure(img3, figure=f, subplot=ax3.get_position().bounds); fig3.show_grayscale(invert=True) 
    
    fig0.axis_labels.hide_x(); fig0.axis_labels.hide_y(); fig0.tick_labels.hide_x(); fig0.tick_labels.hide_y() 
    fig1.axis_labels.hide_x(); fig1.axis_labels.hide_y(); fig1.tick_labels.hide_x(); fig1.tick_labels.hide_y() 
    fig2.axis_labels.hide_x(); fig2.axis_labels.hide_y(); fig2.tick_labels.hide_x(); fig2.tick_labels.hide_y() 
    fig3.axis_labels.hide_x(); fig3.axis_labels.hide_y(); fig3.tick_labels.hide_x(); fig3.tick_labels.hide_y() 
    
    f.savefig('test.png') 
    

    재미있는 점 ... nordev가 제안한 것과 같은 for 루프를 사용하면 4 개의 모든 플롯이 2 차가 아니게됩니다.

    import matplotlib 
    matplotlib.use('Agg') 
    import matplotlib.pyplot as plt 
    from matplotlib import gridspec 
    import aplpy 
    
    f=plt.figure() 
    gs=gridspec.GridSpec(1,4) 
    #img0,... are strings representing the image path 
    img_list=[img0, img1, img2, img3] 
    
    for i in range(0,4): 
        ax=plt.subplot(gs[0,i]) 
    
        ax.set_aspect('equal') 
        ax.axes.get_xaxis().set_ticks([]); ax.axes.get_yaxis().set_ticks([]) 
    
        fig=aplpy.FITSFigure(img_list[i], figure=f, subplot=ax.get_position()) 
        fig.show_grayscale(invert=True) 
    
        fig.axis_labels.hide_x(); fig.axis_labels.hide_y() 
        fig.tick_labels.hide_x(); fig.tick_labels.hide_y() 
    
    f.savefig('test.png') 
    
  • +0

    변수'img0','img1','img2' 및'img3'에는 무엇이 할당되어 있습니까? 이미지 경로를 나타내는 문자열? 참고 사항. 명시 적으로 모든 것을 네 번 입력하는 대신 루프를 사용하면 오류가 발생하기 쉽고 Pythonic이 더 많습니다. – hooy

    +0

    예, img0, img1, img2 및 img3은 이미지 경로를 나타내는 문자열입니다. 분명히 for 루프를 사용하면 좋을 것입니다.) 죄송합니다. –

    +0

    'ax.set_aspect ('equal', adjustable = 'box-forced')'를 사용해보십시오. 공유 된 축이 있다면 도움이 될 수 있습니다. – tacaswell

    답변

    0

    코드와 첫 번째 문제는 라인을

    ax=plt.subplot(gs[0,i]) 
    

    새로운 축는 독립적 FITSFigure 개체에서 사용 축의 조작되는 오브젝트를 생성이다. Axes를 수정하고 싶다면 ax 객체 대신에 문서화되지 않은 fig._ax1 객체를 사용할 수 있습니다. YMMV하지만 matplotlib의 API 중 일부는 aplpy에 의해 무시 (또는 정지)됩니다. 이 변환을 사용하면 WCSAxes으로 바뀔 것입니다.

    여러분이 만드는 도끼 개체를 사용하는 유일한 방법은 FITSFigure()으로 전달할 수있는 위치를 제공하는 것입니다. 또는 GridPpec을 subplot = 매개 변수와 함께 직접 사용할 수 있도록하기 위해 pull request을 제출했습니다.

    문제가 대칭이 아닌 서브 플로트의 기본 위치와 관련되어있을 수 있습니다. rcParams의 figure.subplot.leftfigure.subplot.right을 참조하십시오. 시도 :

    gs=gridspec.GridSpec(1, 4, left=0.1, right=0.9)