【发布时间】:2022-01-02 10:28:43
【问题描述】:
- 如何为
seaborn.kdeplot或seaborn.displot和kind='kde'中的每个hue组分配不同的linestyle?- 坐标轴级别和图形级别选项都将接受
linestyle/ls的str,这适用于所有hue组。
- 坐标轴级别和图形级别选项都将接受
import seaborn as sns
import matplotlib.pyplot as plt
# load sample data
iris = sns.load_dataset("iris")
# convert data to long form
im = iris.melt(id_vars='species')
# axes-level plot works with 1 linestyle
fig = plt.figure(figsize=(6, 5))
p1 = sns.kdeplot(data=im, x='value', hue='variable', fill=True, ls='-.')
# figure-level plot works with 1 linestyle
p2 = sns.displot(kind='kde', data=im, x='value', hue='variable', fill=True, ls='-.')
kdeplot
displot
复习问题
-
How to set the line style for each kdeplot in a jointgrid 不处理
hue组。 -
How to automatically alternate or cycle linestyles in seaborn regplot? 不处理
hue组并遍历每个唯一组。 -
Dotted Seaborn distplot 不处理
hue组并遍历每个唯一组。 -
change line style in seaborn facet grid
hue_kws不是有效选项。
【问题讨论】:
标签: python matplotlib seaborn