如何在seaborn中并排绘制两个计数图?

use*_*696 16 python matplotlib pandas seaborn

我试图绘制两个显示击球和保龄球计数的计票图.我尝试了以下代码:

l=['batting_team','bowling_team']
for i in l:
    sns.countplot(high_scores[i])
    mlt.show()
Run Code Online (Sandbox Code Playgroud)

但通过使用这个,我得到两个一个在另一个下面的情节.我如何让他们并排订购?

Rob*_*bie 30

像这样的东西:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

batData = ['a','b','c','a','c']
bowlData = ['b','a','d','d','a']

df=pd.DataFrame()
df['batting']=batData
df['bowling']=bowlData


fig, ax =plt.subplots(1,2)
sns.countplot(df['batting'], ax=ax[0])
sns.countplot(df['bowling'], ax=ax[1])
fig.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这个想法是指定图中的子图 - 有很多方法可以做到这一点,但上面的工作正常.


Rav*_*i G 6

import matplotlib.pyplot as plt
l=['batting_team', 'bowling_team']
figure, axes = plt.subplots(1, 2)
index = 0
for axis in axes:
  sns.countplot(high_scores[index])
  index = index+1
plt.show()
Run Code Online (Sandbox Code Playgroud)