2017-08-10 34 views
1

seaborn box plot有whis='range'可以繪製最小/最大異常值,但小提琴繪圖在其文檔中沒有。我如何在小提琴中使用boxplot參數?當然如何使用boxplot的whisker參數在小提琴海圖上繪製海雀?

import matplotlib.pyplot as plt 
import seaborn as sns 
import numpy as np 

a=[195.0, 245.0, 142.0, 237.0, 153.0, 238.0, 168.0, 145.0, 229.0, 138.0, 176.0, 116.0, 252.0, 148.0, 199.0, 162.0, 134.0, 163.0, 130.0, 339.0, 152.0, 208.0, 152.0, 192.0, 163.0, 249.0, 113.0, 176.0, 123.0, 189.0, 150.0, 207.0, 184.0, 153.0, 228.0, 153.0, 170.0, 118.0, 302.0, 197.0, 211.0, 159.0, 228.0, 147.0, 166.0, 156.0, 167.0, 147.0, 126.0, 155.0, 138.0, 159.0, 139.0, 111.0, 133.0, 134.0, 131.0, 156.0, 240.0, 207.0, 150.0, 207.0, 265.0, 151.0, 173.0, 157.0, 261.0, 186.0, 195.0, 158.0, 272.0, 134.0, 221.0, 131.0, 252.0, 148.0, 178.0, 206.0, 146.0, 217.0, 159.0, 190.0, 156.0, 172.0, 159.0, 141.0, 167.0, 168.0, 218.0, 191.0, 207.0, 164.0] 

fig, axes = plt.subplots() 

# Seaborn violin plot 
#sns.violinplot(data=a, whis='range') doesn't work 
sns.violinplot(data=a) 

# Normal boxplot has full range, same in Seaborn boxplot 
# axes.boxplot(a, whis='range') 

plt.show() 
+0

正是你想導致對violinplot了'WHIS ='range''說法? – ImportanceOfBeingErnest

+0

@ImportanceOfBeingErnest我希望boxplot(在小提琴劇場內)最小/最大的鬍鬚能夠到達小提琴劇情的頂部和底部,這可以通過在普通盒子上使用'whis ='range'來實現。 – Anderson

+0

後期編輯,但我的意思是當它觸及小提琴情節的頂部和底部時'sns.violinplot(data = a,cut = 0)' – Anderson

回答

1

該解決方案可以疊加正常箱線圖,其中確實有whis='range'參數可用,通過seaborn小提琴情節。

import matplotlib.pyplot as plt 
import seaborn as sns 
import numpy as np 

a=[195.0, 245.0, 142.0, 237.0, 153.0, 238.0, 168.0, 145.0, 229.0, 138.0, 176.0, 116.0, 252.0, 148.0, 
    199.0, 162.0, 134.0, 163.0, 130.0, 339.0, 152.0, 208.0, 152.0, 192.0, 163.0, 249.0, 113.0, 176.0, 
    123.0, 189.0, 150.0, 207.0, 184.0, 153.0, 228.0, 153.0, 170.0, 118.0, 302.0, 197.0, 211.0, 159.0, 
    228.0, 147.0, 166.0, 156.0, 167.0, 147.0, 126.0, 155.0, 138.0, 159.0, 139.0, 111.0, 133.0, 134.0, 
    131.0, 156.0, 240.0, 207.0, 150.0, 207.0, 265.0, 151.0, 173.0, 157.0, 261.0, 186.0, 195.0, 158.0, 
    272.0, 134.0, 221.0, 131.0, 252.0, 148.0, 178.0, 206.0, 146.0, 217.0, 159.0, 190.0, 156.0, 172.0, 
    159.0, 141.0, 167.0, 168.0, 218.0, 191.0, 207.0, 164.0] 

fig, axes = plt.subplots() 

# Seaborn violin plot 
sns.violinplot(data=a, color="#af52f4", inner=None, linewidth=0, saturation=0.5) 

# Normal boxplot has full range, same in Seaborn boxplot 
axes.boxplot(a, whis='range', positions=np.array([0]), 
      showcaps=False,widths=0.06, patch_artist=True, 
      boxprops=dict(color="indigo", facecolor="indigo"), 
      whiskerprops=dict(color="indigo", linewidth=2), 
      medianprops=dict(color="w", linewidth=2)) 

axes.set_xlim(-1,1) 
plt.show() 

enter image description here

+0

我希望有一個更直觀的方法,但是這個工作方式就像好。 – Anderson