2013-01-01 2 views
0

이 함수를 설명서에서 사용하여 matplotlib과 함께 멋진 플롯을 만듭니다.AxisGrid를 사용하여 플로팅 할 때 MinorLocator 변경

def demo_grid_with_single_cbar(fig): 
    """ 
    A grid of 2x2 images with a single colorbar 
    """ 
    grid = AxesGrid(fig, 132, # similar to subplot(132) 
        nrows_ncols = (2, 2), 
        axes_pad = 0.0, 
        share_all=True, 
        label_mode = "L", 
        cbar_location = "top", 
        cbar_mode="single", 
        ) 

    Z, extent = get_demo_image() 
    for i in range(4): 
     im = grid[i].imshow(Z, extent=extent, interpolation="nearest") 
    #plt.colorbar(im, cax = grid.cbar_axes[0]) 
    grid.cbar_axes[0].colorbar(im) 

    for cax in grid.cbar_axes: 
     cax.toggle_label(False) 

    # This affects all axes as share_all = True. 
    grid.axes_llc.set_xticks([-2, 0, 2]) 
    grid.axes_llc.set_yticks([-2, 0, 2]) 

마이너 로케이터를 변경하고 싶습니다. 하지만 코드를 변경할 위치가 없습니다. 하나의 그래픽에서 Axes 객체를 조작한다면 어디에 사용합니까? AxesGrid를 사용하면 길을 잃어 버립니다.

majorLocator = MultipleLocator(50) 
majorFormatter = FormatStrFormatter('%d') 
minorLocator = MultipleLocator(10) 
ax.yaxis.set_major_locator(majorLocator) 
ax.yaxis.set_major_formatter(majorFormatter) 
ax.yaxis.set_minor_locator(minorLocator) 

문제가 해결 된 후 편집하십시오. 결과는 다음 그림과 같을 것입니다. 작은 눈금을 확인하십시오!

결과는 http://i.stack.imgur.com/o1YPK.png

어쩌면 다른 사람을 추가 할 수 있습니다이 이미지처럼 보일 것입니다. 내 명성 크레딧으로는 충분하지 않기 때문에 그럴 수 없습니다.

+0

어떤 matplotlib 버전을 사용하고 있습니까? – tacaswell

+0

버전 1.1.1rc – elcojon

답변

0

경고는 main page에 유의하십시오. matplotlib의 새 버전이 있으면이 방법이 유용합니다.

from mpl_toolkits.axes_grid1 import ImageGrid 

def get_demo_image(): 
    import numpy as np 
    from matplotlib.cbook import get_sample_data 
    f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False) 
    z = np.load(f) 
    # z is a numpy array of 15x15 
    return z, (-3,4,-4,3) 

def demo_grid_with_single_cbar(fig): 
    """ 
    A grid of 2x2 images with a single colorbar 
    """ 
    grid = ImageGrid(fig, 132, # similar to subplot(132) 
        nrows_ncols = (2, 2), 
        axes_pad = 0.0, 
        share_all=True, 
        label_mode = "L", 
        cbar_location = "top", 
        cbar_mode="single", 
        ) 

    Z, extent = get_demo_image() 
    for i in range(4): 
     im = grid[i].imshow(Z, extent=extent, interpolation="nearest") 
    #plt.colorbar(im, cax = grid.cbar_axes[0]) 
    grid.cbar_axes[0].colorbar(im) 

    for cax in grid.cbar_axes: 
     cax.toggle_label(False) 

    # This affects all axes as share_all = True. 
    grid.axes_llc.set_xticks([-2, 0, 2]) 
    grid.axes_llc.set_yticks([-2, 0, 2]) 

    for i in range(4): 
     ax = grid[i] 
     ax.yaxis.set_minor_locator(MultipleLocator(.5)) 
+0

을 사용하고 있습니다. 색상 표시 줄에 레이블을 추가하는 방법을 알고 있습니까? – elcojon

+0

@elcojon 당신은 새로운 질문으로 물어봐야합니다. – tacaswell

관련 문제