Seaborn distplot 与来自不同数组的 rugplot
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()
使用 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()