Skip to main content
 首页 » 编程设计

python之在 seaborn factorplot 中绘制虚线

2025年05月04日17落叶无声

import seaborn as sns 
sns.set(style="ticks") 
exercise = sns.load_dataset("exercise") 
g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise) 

在上图中,有没有办法将其中一种线型绘制为虚线,例如将“休息”线绘制为虚线。

请您参考如下方法:

使用linestyles 参数并选择desired type of line根据 matplotlib:

import seaborn as sns 
import matplotlib.pylab as plt 
sns.set(style="ticks") 
exercise = sns.load_dataset("exercise") 
g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise, linestyles=[":", "-","-"]) 
plt.show()