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
CodePudding user response:
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.
CodePudding user response:
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()