虚线 Seaborn 分布图

Shi*_*Dua 3 python matplotlib seaborn jupyter-notebook

我有一个 seaborn displot 看起来像这样 在此处输入图片说明

我想画一些虚线。我怎样才能做到这一点?我尝试以 2 种不同的方式使用 linestyle 并出现错误

#### approach 1
for x, m in x_list:
    sns.distplot(x, hist=False, label=m, linestyle='--')
#### approach 2
for x, m in x_list:
    sns.distplot(x, hist=False, label=m, kde_kws={'linestyle':'--'})

TypeError: distplot() got an unexpected keyword argument 'linestyle'
Run Code Online (Sandbox Code Playgroud)

Imp*_*est 5

使用的第二种方法kde_kws={'linestyle':'--'}适用于 seaborn 8.1。也许你想更新。

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

x_list = [np.random.rayleigh(1+i/2., size=35) for i in range(4)]

for x in x_list:
    sns.distplot(x, hist=False, kde_kws={'linestyle':'--'})

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明