簡體   English   中英

Dotted Seaborn distplot

[英]Dotted Seaborn distplot

我有一個看起來像這樣的seaborn displot 在此輸入圖像描述

我想做一些點綴的線條。 我怎樣才能做到這一點? 我嘗試以兩種不同的方式使用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'

您可以使用ax.lines從seaborn distplot返回的軸中獲取Line2D對象的列表。 然后,使用set_linesytle遍歷這些對象,以設置所需的linestyle。

例如:

import seaborn as sns

x = np.random.randn(100)
ax = sns.distplot(x, hist=False)

[line.set_linestyle("--") for line in ax.lines] 

plt.show()

在此輸入圖像描述

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

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM