首页 > 解决方案 > seaborn 散点图绘制的日期比原始数据中的日期多

问题描述

我的数据集包含 2018 年的数据。我尝试绘制一个简单的散点图,出于某种原因,绘制了 2000 年至 2018 年的 seaborn 图。我还没有找到解决方案。

seaborn lineplot 作品。

Matplotlib scatter 也可以正常工作。

代码:

plt.figure(figsize = (7,7), dpi = 200)
sns.scatterplot(x = df["Date"].values,
           y = df["values"].values)
plt.show()

在此处输入图像描述

标签: pythonseaborn

解决方案


.set()您可以使用绘图手动设置 x 轴的范围。

ax = sns.scatterplot(x = df["Date"].values, y = df["values"].values)
ax.set(xlim = ('2018-01-01', '2018-12-31'))

推荐阅读