Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Seaborn距离图与来自不同阵列的rugplot_Python_Numpy_Matplotlib_Seaborn - Fatal编程技术网

Python Seaborn距离图与来自不同阵列的rugplot

Python Seaborn距离图与来自不同阵列的rugplot,python,numpy,matplotlib,seaborn,Python,Numpy,Matplotlib,Seaborn,使用seaborn制作地毯远距图很容易: 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 plot下显示来自不同发行版的地毯,rug\u array,该怎

使用seaborn制作地毯远距图很容易:

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 plot下显示来自不同发行版的地毯,
rug\u array
,该怎么办

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

答案应显示曲线
x
,地毯图刻度为-2、-1,0,1,2,2.1和3。

Seaborn提供了绘制地毯图的功能。我们的想法是使用这个函数

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()

不想让这变得更复杂,但如果rug_阵列的比例与当前的x轴(如log10)不同,我如何添加单独的轴来匹配rug_阵列?如果需要,我可以将其作为不同的问题发布。您可以使用
ax2=ax.twny()
添加一个新轴,并通过
sns.rugplot(…,ax=ax2)
将rugplot绘制到该轴上。然而,我怀疑这个阴谋是否容易理解。如果这对您没有帮助,那么发布一个新问题并给出准确的问题描述可能是有意义的。