Home > Back-end >  Seaborn is plotting a line different from Matplotlib
Seaborn is plotting a line different from Matplotlib

Time:02-16

Following is the simple dataset =

x = [7.5, 7.5, 17.5]
y = [393.198, 351.352, 351.352]

The output plot I am looking for is correctly produced by -

plt.plot(x,y) #right angle looking plot

However, I get weird plot when I do this in Seaborn -

sns.lineplot(x=x,y=y)

I don't understand why Seaborn is producing this plot and how do I modify the Seaborn code to get the plot produced by Matplotlib?

CodePudding user response:

Seaborn's lineplot is made to infer relationships between the x/y datasets. Thus it is computing an estimator (by default the mean) to aggregate the data on common x.

Here, as you have two times 7.5 as x, it aggregates the two points into a single y that is the mean of 393.198 and 351.352.

You're simply not using seaborn's function for what it is made. If you want the raw matplotlib graph, use matplotlib directly.

CodePudding user response:

Seaborn try doing some estimation and sorting with the data for better visualization of the relationship between x and y (document).

The below code produce the same chart with matplotlib

sns.lineplot(x=x,y=y, estimator=None, sort=False)

  • Related