2017-04-05 128 views
1

我想繪製一個離散概率分佈(MWE以下)。如何繪製Seaborn的離散概率分佈?

爲了保持圖形一致,我想使用seaborn

from pandas import DataFrame 

x = [2,3,5] 
freq = [0.3,0.2,0.5] 
df = DataFrame({'val.':x,'freq.':freq}) 
df.set_index('val.') 

dataframe

是否有任何方式來產生這個分佈的barplot(不是生成具有該分佈數據等)?

回答

1

一種選擇是使用內置的數據幀繪製功能:

import pandas as pd 
import seaborn as sns 
x = [2,3,5] 
freq = [0.3,0.2,0.5] 
df = pd.DataFrame({'val.':x,'freq.':freq}) 
df.set_index('val.')['freq.'].plot.bar(rot=0) 

主要生產:

a <code>pandas</code> bar plot

另一種選擇使用seaborn

sns.barplot(data = df,x='val.',y='freq.') 

<code>seaborn</code> bar plot