简体   繁体   中英

Python seaborn lineplot missing values on the plot

I am trying to create a lineplot using seaborn and it appears that for the specific case of points I have, the plot is missing some points on the plotted line leading to an incorrect plot. The code snippet is shown below

import matplotlib.pyplot as plt
import seaborn as sns

x = [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.6, 0.8, 1.0]
y = [0.0, 0.21, 0.41, 0.81, 1.0, 1.0, 1.0, 1.0, 1.0]


ax = sns.lineplot(x = x, y = y)
sns.scatterplot(x = x, y = y, ax = ax)
plt.show()

The resulting plot is shown below

在此处输入图像描述

Any idea why this might be happening? I tried using seaborn versions 0.11.2 and 0.12.2

When using lineplot , the documentation says that:

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.

So, you instead need to have:

ax = sns.lineplot(x=x, y=y, estimator=None)

to stop the aggregation happening.

Do you have to use seaborn? If not, use the matplotlib directly:

import matplotlib.pyplot as plt


x = [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.6, 0.8, 1.0]
y = [0.0, 0.21, 0.41, 0.81, 1.0, 1.0, 1.0, 1.0, 1.0]

plt.plot(x,y, marker='o')
plt.show()

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