简体   繁体   中英

Seaborn distplot with rugplot from different array

Making a distplot with a rug using seaborn is easy:

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 . But what if I want to display the rug from a different distribution, rug_array , under the dist plot of x ?

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.

Seaborn provides a function rugplot to draw the 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()

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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