2013-11-20 5 views
2

서브 플로트 그림의 맨 아래에 서브 플로트를 추가하려고합니다. 내가 가지고있는 문제는 모든 하위 집합의 첫 번째 집합이 자신의 x 축을 공유하지만 맨 아래는 공유하지 않는다는 것입니다.다른 사람들이 할 때 x 축을 공유하지 않는 서브 플로트 추가

channels은 x 축을 공유하려는 하위 그림입니다.

그래서 어떻게 x 축을 공유하지 않는 서브 플로트를 추가 할 수 있습니까? 이 내 코드입니다 :

그들이 마지막으로 부가 적 줄거리의 x 축 shareing 때문에이 코드는 하지 작업을 수행
def plot(reader, tdata): 
    '''function to plot the channels''' 

channels=[] 
     for i in reader: 
     channels.append(i) 

    fig, ax = plt.subplots(len(channels)+1, sharex=False, figsize=(30,16), squeeze=False) 
    plot=0 
    #where j is the channel name 
    for i, j in enumerate(reader): 

     y=reader["%s" % j] 
     ylim=np.ceil(np.nanmax(y)) 
     x=range(len((reader["%s" % j]))) 
     ax[plot,0].plot(y, lw=1, color='b') 
     ax[plot,0].set_title("%s" % j) 
     ax[plot,0].set_xlabel('Time/s') 
     ax[plot,0].set_ylabel('%s' % units[i]) 
     ax[plot,0].set_ylim([np.nanmin(y), ylim+(ylim/100)*10]) 
     plot=plot+1 

    ###here is the new subplot that doesn't want to share the x axis### 
    ax[plot, 0].plot() 
    plt.tight_layout() 
    plt.show() 

. 채널의 길이는 코드에서 이전에 지정한 내용에 따라 달라집니다.

숫자가 일정하지 않아도 add_subplot을 사용하는 것이 유효한 옵션입니까? 조에 어떤 도움

편집 이미지에 대한 너무 많은

감사 :

enter image description here

답변

3

는이 경우 직접 fig.add_subplot를 사용하는 것이 가장 쉬운 방법이다. 간단한 예를 들어

:

import matplotlib.pyplot as plt 

fig = plt.figure(figsize=(6, 8)) 

# Axes that share the x-axis 
ax = fig.add_subplot(4, 1, 1) 
axes = [ax] + [fig.add_subplot(4, 1, i, sharex=ax) for i in range(2, 4)] 

# The bottom independent axes 
axes.append(fig.add_subplot(4, 1, 4)) 

# Let's hide the tick labels for all but the last shared-x axes 
for ax in axes[:2]: 
    plt.setp(ax.get_xticklabels(), visible=False) 

# And plot on the first subplot just to demonstrate that the axes are shared 
axes[0].plot(range(21), color='lightblue', lw=3) 

plt.show() 

enter image description here

+0

이 코드를 실행하면, 규모가 범위를 음모 변경되지 않습니다, 내 공유 축 배율은 0.06로 유지됩니다. 내가 당신에게 이미지를 보여줄 수는 있지만 어디서 올릴 지 확신하지 못합니다. –

+0

@AshleighClayton - 질문에 추가하거나 imgur (또는 유사한 이미지 공유 사이트)에 게시하고 링크를 댓글로 추가 할 수 있습니다. 네가하려는 일을 오해하고 있을지도 모른다. –

+0

필자는 코드를 테스트하기 위해 완전히 그대로 복사했습니다. 내 질문에 이미지를 넣을거야. 도움을 주셔서 감사합니다 –