簡體   English   中英

如何在 seaborn 中並排繪制兩個計數圖?

[英]How do I plot two countplot graphs side by side in seaborn?

我試圖繪制兩個計數圖,顯示擊球和保齡球的計數。 我嘗試了以下代碼:

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

但是通過使用 this ,我得到了兩個圖一個在另一個下面。 我怎樣才能讓它們並排訂購?

像這樣的東西:

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()

在此處輸入圖片說明

這個想法是在圖中指定子圖 - 有很多方法可以做到這一點,但上述方法可以正常工作。

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM