[英]Seaborn distplot with rugplot from different array
使用seaborn用地毯制作一個distplot很容易:
import seaborn as sns, numpy as np
%matplotlib inline
sns.set(rc={"figure.figsize": (8, 4)}); np.random.seed(0)
x = np.random.randn(100)
ax = sns.distplot(x, rug=True)
上面的地圖反映了分布x
。 但是如果我想在x
的dist曲線下顯示來自不同發行版rug_array
的地毯呢?
rug_array = np.array([-2.0, -1, 0, 1, 2, 2.1, 3])
答案應顯示曲線x
的圖,其中地圖繪制標記為-2,-1,0,1,2,2.1和3。
Seaborn提供了一個功能rugplot
繪制rugplot。 想法是使用這個功能。
import seaborn as sns
import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
x = np.random.randn(100)
rug_array = np.array([-2.0, -1, 0, 1, 2, 2.1, 3])
ax = sns.distplot(x, rug=False)
sns.rugplot(rug_array, height=0.05, axis='x', ax=ax)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.