简体   繁体   English

Seaborn distplot与来自不同阵列的rugplot

[英]Seaborn distplot with rugplot from different array

Making a distplot with a rug using seaborn is easy: 使用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)

The rug plot above reflects the distribution x . 上面的地图反映了分布x But what if I want to display the rug from a different distribution, rug_array , under the dist plot of x ? 但是如果我想在x的dist曲线下显示来自不同发行版rug_array的地毯呢?

rug_array = np.array([-2.0, -1, 0, 1, 2, 2.1, 3])

The answer should display a plot of the curve x with rug plot ticks at -2,-1, ,0, 1, 2, 2.1, and 3. 答案应显示曲线x的图,其中地图绘制标记为-2,-1,0,1,2,2.1和3。

Seaborn provides a function rugplot to draw the rugplot. Seaborn提供了一个功能rugplot绘制rugplot。 The idea is to use this function. 想法是使用这个功能。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM