2017-02-11 1 views
1

최근에 matplotlib 및 seaborn을 사용하여 그래프를 그렸습니다. 이 결과는 다음과 같다 내가 지금까지seaborn을 사용하여 서브 플롯 크기 조정

count = 1 
l=[13,0,47,29,10] 
plt.figure(figsize=(30,40)) 

for ww in l: 
    temp_dict = defaultdict(list) 
    entropies = list() 
    for k,v in df.ix[ww].iteritems(): 
     e = 0 
     for i in v: 
      temp_dict[k].append(float(i)) 
      if not float(i) == 0: 
       e += -1.0*float(i)*log10(float(i)) 
     entropies.append(e) 

    y = entropies 
    x=(range(len(entropies))) 
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) 

    plt.subplot(len(lista_autori),2,count) 
    tdf = pd.DataFrame.from_dict(temp_dict, orient='columns') 
    a = tdf.dropna() 
    sns.set(font_scale=2) 
    #sns.factorplot(size=2, aspect=1) 
    sns.heatmap(a,linewidths=.5,cmap="RdBu_r") 
    plt.xlabel(ur'year') 
    plt.ylabel(ur'$PACS$') 
    count +=1 

    plt.subplot(len(lista_autori),2,count) 
    plt.plot(x,y) 
    x1 = (range(28)) 
    y1 = [slope*i + intercept for i in x1] 
    plt.plot(x1,y1) 
    count +=1 


plt.tight_layout(); 

을 쓴 코드 :

enter image description here

내가 왼쪽에있는 행의 2/3을 할당, 각 행의 크기를 조정하고자하는

옆 그림, 나머지는 오른쪽 그림. 나는 here 주어진 답변을 보려고했지만 ax와 seaborn의 히트 맵을 혼합해야 할 때 어려움을 발견했습니다. 어떤 도움이나 다른 해결책?

답변

1

linked question에 대한 대답은 GridSpec을 사용하여 불균등 한 열 너비의 표를 얻는 방법을 직접 알려줍니다. 나는 여기서 차이점을별로 보지 못했지만 어버 튼 히트 맵 (seaborn heatmap), 둘 이상의 행 및 "도끼"를 사용하지 않으므로 다음과 같이 이해할 수 있습니다.

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import gridspec 
import seaborn as sns 

# generate some data 
x = np.arange(0, 10, 0.2) 
y = np.sin(x) 
X = np.random.rand(3,4) 

fig = plt.figure(figsize=(8, 6)) 
gs = gridspec.GridSpec(5, 2, width_ratios=[2, 1]) 

for i in range(5): 
    plt.subplot(gs[i*2+0]) 
    sns.heatmap(X) 
    plt.subplot(gs[i*2+1]) 
    plt.plot(x,y) 

plt.show() 
관련 문제