2012-01-19 3 views
2

사진 부가 적 줄거리 크기 파이썬

에서 볼 수있는 나는 순간에 직면하고있다 문제는 왼쪽 하단의 플롯에 Y 축 -100에서 +600까지 큰에 방법인가요 . 이것을 수정할 수있는 방법이 있습니까? 나는 많이 시도했지만 그것을 찾을 수 없었다. axScatter.set_ylim (-5, 5) 을 그리고 축 축소하지만, 다음이 발생합니다 :

# the random data 
    x = np.random.randint(0,500,100000) 
    y = np.random.randn(100000) 



    fig = plt.figure(1, figsize=(5.5,5.5)) 

    from mpl_toolkits.axes_grid1 import make_axes_locatable 

    # the scatter plot: 
    axScatter = plt.subplot(111) 
    axScatter.scatter(x, y) 
    axScatter.set_aspect(1.) 
    # create new axes on the right and on the top of the current axes 
    # The first argument of the new_vertical(new_horizontal) method is 
    # the height (width) of the axes to be created in inches. 
    divider = make_axes_locatable(axScatter) 
    axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter) 
    axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter) 

    # make some labels invisible 
    plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(), 
      visible=False) 

    # now determine nice limits by hand: 
    binwidth = 0.25 
    print np.max(np.fabs(y)) 
    print np.max(np.fabs(x)) 

    xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))]) 

    print xymax #will always be gene length wich should not be 

    lim = (int(xymax/binwidth) + 1) * binwidth 
    print lim 
    bins = np.arange(0, lim + binwidth, binwidth) 
    print bins 

    #two histo grams, should stay of this? 
    axHistx.hist(x, bins=bins) 
    axHisty.hist(y, bins=bins, orientation='horizontal') 

    # the xaxis of axHistx and yaxis of axHisty are shared with axScatter, 
    # thus there is no need to manually adjust the xlim and ylim of these 
    # axis. 

    #axHistx.axis["bottom"].major_ticklabels.set_visible(False) 
    for tl in axHistx.get_xticklabels(): 
     tl.set_visible(False) 
    axHistx.set_yticks([0, 50, 100,200]) 

    #axHisty.axis["left"].major_ticklabels.set_visible(False) 
    for tl in axHisty.get_yticklabels(): 
     tl.set_visible(False) 
    axHisty.set_xticks([0, 50000, 100000]) 

    plt.draw() 
    plt.show() 
    plt.savefig('.png') 

는 이제 사용할 수 있습니다 삭제 곳은 어떻게 든 모든 의견으로 재 게시물입니다 squased

...

답변

5

코드와 코드가 혼합 된 대안을 아래에서 찾으십시오. matplotlib examples. 나는이 시점에서 시작할 수 있다고 생각 , 한계를 계산 나는 수동으로 계산 한 : 바로 그것으로 뛰어들 것

enter image description here

from matplotlib import pyplot as plt 
from mpl_toolkits.axes_grid1 import make_axes_locatable 
import numpy as np 

x = np.random.randint(0, 500, 100000) 
y = np.random.randn(100000) 

# definitions for the axes 
left, width = 0.1, 0.65 
bottom, height = 0.1, 0.65 
bottom_h = left_h = left + width + 0.02 

rect_scatter = [left, bottom, width, height] 
rect_histx = [left, bottom_h, width, 0.2] 
rect_histy = [left_h, bottom, 0.2, height] 

fig = plt.figure(1, figsize=(5.5,5.5)) 

axScatter = plt.axes(rect_scatter) 
axHistx = plt.axes(rect_histx) 
axHisty = plt.axes(rect_histy) 

# the scatter plot: 
axScatter.scatter(x, y) 

binwidth = 0.25 
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))]) 
lim = (int(xymax/binwidth) + 1) * binwidth 

axScatter.set_xlim((0, lim)) 
axScatter.set_ylim((-5, 10))  # <-- controls y axis. Values should be calculated. 

bins = np.arange(-lim, lim + binwidth, binwidth) 
axHistx.hist(x, bins=bins) 
axHisty.hist(y, bins=bins, orientation='horizontal') 

axHistx.set_xlim(axScatter.get_xlim()) 
axHisty.set_ylim(axScatter.get_ylim()) 

#axHistx.axis["bottom"].major_ticklabels.set_visible(False) 
for tl in axHistx.get_xticklabels(): 
    tl.set_visible(False) 
axHistx.set_yticks([0, 50, 200]) 

#axHisty.axis["left"].major_ticklabels.set_visible(False) 
for tl in axHisty.get_yticklabels(): 
    tl.set_visible(False) 
axHisty.set_xticks([0, 10000, 20000]) 

plt.show() 
+0

감사합니다! 고마워요 – Jasper

+0

완벽하게 작동합니다! – Jasper