mayankkaizen
mayankkaizen

Reputation: 327

Seaborn is plotting a line different from Matplotlib

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?

Upvotes: 0

Views: 1188

Answers (2)

Will
Will

Reputation: 176

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)

Upvotes: 3

mozway
mozway

Reputation: 262274

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.

Upvotes: 1

Related Questions