How do I increase the line thickness for sns.lineplot?
Asked Answered
J

4

33

I have a few seaborn lineplots and I can't figure out how to increase the width of my lines.

Here is my code

#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()

enter image description here

Jarad answered 30/6, 2020 at 22:40 Comment(0)
V
49

As you can see from seaborn.lineplot documentation, the function accepts matplotlib.axes.Axes.plot() arguments, which means you can pass the same arguments you can to matplotlib function in this documentation.

If you want to simply adjust the width of your lineplots I find this the easiest: pass an argument linewidth = your_desired_line_width_in_float , for example, linewidth = 1.5 in your sns.lineplot() functions.

You can find additional possible arguments in the documentations linked.

Example output on random data:

seaborn.lineplot() without linewdith argument provided searbon.lineplot() without linewdith argument

seaborn.lineplot() with linewidth = 3 seaborn.lineplot() with linewidth = 3

Venge answered 30/6, 2020 at 22:56 Comment(0)
P
11

For those of you who are drawing vertical lines and wondering why changing the linewidth parameter seems to have no impact, the answer lies in lineplot's estimator parameter.

For example,

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

produces

a graph with a thin vertical line

While

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

produces

a graph with a thick vertical line

The documentation states "by default, the plot aggregates over multiple y values at each value of x and shows an estimate of the central tendency and a confidence interval for that estimate". The thin line is an artefact of that aggregation. And by setting estimator to None, "all observations will be drawn."

For more discussion, see the question Vertical line artefacts in 2D lineplot

Platyhelminth answered 25/3, 2022 at 3:18 Comment(0)
U
1

You need to specify the linewidth parameter = desired width

Ultan answered 1/7, 2020 at 4:51 Comment(0)
R
0
sns.lineplot([data], linewidth = __ )
Ruby answered 30/11, 2023 at 22:53 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Rundlet

© 2022 - 2024 — McMap. All rights reserved.