2016-07-21 5 views
0

matplotlib의 AxesGrid를 사용하여 두 개의 imshow 플롯을 오버레이하는 플롯을 만들고 각 이미지 컬러 맵에 대해 별도의 컬러 막대를 나란히 배치합니다. this question/answer에서 pyplot.colorbar()를 사용하면 자동으로 두 번째 색상 막대가 첫 번째 색상 막대 옆에 표시된다는 것을 볼 수 있지만 AxesGrid에서는 작동하지 않는 것으로 보입니다.AxesGrid를 사용하여 두 개의 개별 컬러 막대로 두 개의 imshow (오버레이)를 그릴 수 있습니까?

import matplotlib.pyplot as plt 
    from mpl_toolkits.axes_grid1 import AxesGrid 

    fig = plt.figure(1, facecolor='white',figsize=(10,7.5)) 

    grid = AxesGrid(fig, 111, 
        nrows_ncols=(1, 1), 
        axes_pad=(0.45, 0.15), 
        label_mode="1", 
        share_all=True, 
        cbar_location="right", 
        cbar_mode="each", 
        cbar_size="7%", 
        cbar_pad="2%", 
        ) 

    im = grid[0].imshow(my_image, my_cmap) 
    cbar = grid.cbar_axes[0].colorbar(im) 

    im2 = grid[0].imshow(my_image_overlay, my_cmap2, alpha=0.5) 
    cbar2 = grid.cbar_axes[0].colorbar(im2) 

    plt.show() 

그러나 이것은 두 번째 색조를 보여줍니다. (아마 첫 번째 것을 겹쳐서). 나는 함께 cbar2에 패딩을 재정의하는 시도 :

cbar2 = grid.cbar_axes[0].colorbar(im2, pad=0.5) 

하지만이

두 번째 색상 바를을 상쇄 할 수있는 방법이 있나요 "예기치 않은 키워드 인수 '패드'를 얻었다"에 오류가 발생?

답변

0

나는 당신이 colorbars 두 축하고이를 사용해야 할 수도 있습니다 생각 :

from mpl_toolkits.axes_grid1 import make_axes_locatable 
# create an axes on the right side of ax. The width of cax will be 5% 
# of ax and the padding between cax and ax will be fixed at 0.05 inch. 
divider = make_axes_locatable(ax) 
cax = divider.append_axes("right", size="5%", pad=0.05) 

'을 현재에 동일한 할당 된 공간을 사용하고있는 원인.

관련 문제