How to adjust subplot size in seaborn?
1 2 3 4 5 6 7 8 9 10 | %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 |
这将根据需要输出子图。
但是,当试图通过深加工来实现它时,子图却彼此靠近堆积,如何更改每个子图的大小?
1 2 3 4 5 6 7 8 9 10 | 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 |
您对
然后您可以简单地调用
此外,通过在
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # 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() |
在没有