简体   繁体   中英

Matplotlib plot function output differs from seaborn's lineplot

I want to plot a PDF function given data which follows a normal distribution. Mainly I followed this link.

Now, if I am working on the data created like on that website ( x=np.linspace() ) and I plot it with either seaborn.lineplot() or matplotlib.pyplot.plot() , I get a normal curve as shown on the website linked above. But when I do this with my own data (which I believe is normal, but with a lot more data points) instead of initializing it with np.linspace I get a clear normal curve with seaborn's lineplot and a messy normal curve with matplotlib's plot function .

I have tried to look for default arguments on both functions but couldn't find any (except estimator) which would cause this behavior. The estimator argument of Seaborn's lineplot was the only argument that looked like it could do something like this but setting it to None did not make any difference (and it kind of makes sense I think since the y value is always same for a specific x so averaging out will produce the same value).

I used to think both functions are the same, but then why do they have different output?

The Seaborn lineplot function has the default parameter sort=True .

So unless you tell it not to, it'll order the data for you. This is not something which pyplot.plot() does, instead it'll draw lines between the points in the order provided.

If you want to order the data before plotting it using Pyplot, there's a good solution for how to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM