如何增加 Seaborn Line 的线条粗细

erb*_*020 12 python matplotlib seaborn

我有一些 seaborn 线图,但我不知道如何增加线条的宽度。

这是我的代码

#graph 1
sns.lineplot(x="date", y="nps", data=df_nps, ax=ax1, label="NPS", color='#0550D0')
sns.lineplot(x="date", y="ema28", data=df_nps, ax=ax1, label="EMA28", color='#7DF8F3')
sns.lineplot(x="date", y="ema7", data=df_nps, ax=ax1, label="EMA7", color='orange')

#graph 2
dfz_nps_lineplot = sns.lineplot(x="date", y="nps", data=dfz_nps, ax=ax2, label="NPS", color='#0550D0')
dfz_nps_lineplot = sns.lineplot(x="date", y="ema28", data=dfz_nps, ax=ax2, label="EMA28", color='#7DF8F3')
dfz_nps_lineplot = sns.lineplot(x="date", y="ema7", data=dfz_nps, ax=ax2, label="EMA7", color='orange')

#graph3
dfp_nps_lineplot = sns.lineplot(x="date", y="nps", data=dfp_nps, ax=ax3, label="NPS", color='#0550D0')
dfp_nps_lineplot = sns.lineplot(x="date", y="ema28", data=dfp_nps, ax=ax3, label="EMA28", color='#7DF8F3')
dfp_nps_lineplot = sns.lineplot(x="date", y="ema7", data=dfp_nps, ax=ax3, label="EMA7", color='orange')

# formatting

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

这就是我的线图现在的样子。

https://gyazo.com/1aecfef9e71bfc9d6c0b5f603db93bd1

dm2*_*dm2 12

正如您从seaborn.lineplot文档中看到的,该函数接受 matplotlib.axes.Axes.plot() 参数,这意味着您可以将相同的参数传递给本文档中的matplotlib 函数。

如果您只想调整线图的宽度,我发现这是最简单的:linewidth = your_desired_line_width_in_float例如,linewidth = 1.5在您的sns.lineplot()函数中传递参数。

您可以在链接的文档中找到其他可能的参数。

随机数据的示例输出:

seaborn.lineplot() 没有提供 linewdith 参数 searbon.lineplot() 没有 linewdith 参数

seaborn.lineplot() 线宽 = 3 seaborn.lineplot() 线宽 = 3


Mat*_*ker 11

对于那些正在绘制垂直线并想知道为什么更改linewidth参数似乎没有影响的人,答案在于 lineplot 的estimator参数。

例如,

sns.lineplot(
    x=[1,1],
    y=[1,2],
    linewidth=10 # <- This will have NO impact
)
Run Code Online (Sandbox Code Playgroud)

产生

带有细垂直线的图表

尽管

sns.lineplot(
    x=[1,1],
    y=[1,2],
    estimator=None,
    linewidth=10 # <- This will now have an impact
)
Run Code Online (Sandbox Code Playgroud)

产生

带有粗垂直线的图表

文档指出“默认情况下,该图在每个 x 值处聚合多个 y 值,并显示集中趋势的估计值和该估计值的置信区间”。细线是这种聚合的产物。通过设置estimatorNone“将绘制所有观察结果”。

有关更多讨论,请参阅问题2D lineplot 中的垂直线伪影