2017-01-15 7 views
4
%matplotlib inline 
fig, axes = plt.subplots(nrows=2, ncols=4) 
m = 0 
l = 0 
for i in k: 
    if l == 4 and m==0: 
     m+=1 
     l = 0 
    data1[i].plot(kind = 'box', ax=axes[m,l], figsize = (12,5)) 
    l+=1 

これは、必要に応じてサブプロットを出力します。海底でサブプロットのサイズを調整するには?

Pandas Boxplots

しかしseabornを通してそれを達成しようとすると、サブプロットが互いに近接積層されるが、どのように私は、各サブプロットのサイズを変更できますか?

fig, axes = plt.subplots(nrows=2, ncols=4) 
m = 0 
l = 0 
plt.figure(figsize=(12,5)) 
for i in k: 
    if l == 4 and m==0: 
     m+=1 
     l = 0 
    sns.boxplot(x= data1[i], orient='v' , ax=axes[m,l]) 
    l+=1 

Seaborn Boxplots

+1

マイアップの投票それはめちゃくちゃに見えるというのが私の合意を表し、私はそれを修正する方法さっぱりだが、私は他の誰かができるかどうかを確認したいです。 – piRSquared

答えて

4

plt.figure(figsize=(12,5))へのあなたの呼び出しは、すでに最初のステップからfigを宣言し、あなたは異なる新しい空のフィギュアを作成しています。電話のfigsizeplt.subplotsに設定します。あなたが設定していないので、あなたのプロットのデフォルトは(6,4)です。あなたはすでにあなたの図を作成し、変数figに割り当てました。あなたがその人物に行動したいのであれば、サイズを変更する代わりにfig.set_size_inches(12, 5)をやっていたはずです。

次に、fig.tight_layout()を呼んで、プロットがうまく収まるようにします。

また、axesオブジェクトの配列にflattenを使用すると、軸を反復処理する方がはるかに簡単です。海底から直接データを使用しています。 tight_layoutプロットなし

enter image description here

# I first grab some data from seaborn and make an extra column so that there 
# are exactly 8 columns for our 8 axes 
data = sns.load_dataset('car_crashes') 
data = data.drop('abbrev', axis=1) 
data['total2'] = data['total'] * 2 

# Set figsize here 
fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(12,5)) 

# if you didn't set the figsize above you can do the following 
# fig.set_size_inches(12, 5) 

# flatten axes for easy iterating 
for i, ax in enumerate(axes.flatten()): 
    sns.boxplot(x= data.iloc[:, i], orient='v' , ax=ax) 

fig.tight_layout() 

は少し一緒に壊しています。下記参照。

enter image description here

関連する問題