[英]Seaborn: lineplot looks like a step plot
I'm trying to build a line plot with Seaborn in Jupyter Notebook, using the code below:我正在尝试使用以下代码在 Jupyter Notebook 中使用 Seaborn 构建线图:
import pandas as pd
import seaborn as sns
# load csv
df=pd.read_csv('C:/Users/1/Desktop/graphs/seaborn/Data.csv')
# make sure date is in datetime
df['Date'] = pd.to_datetime(df['Date'], format='%m-%d-%y')
# generate graph
g = sns.lineplot(x="Date", y="Data", data=df)
plt.show()
However, the result looks like this:但是,结果如下所示:
whereas the desired output is as follows (built in Excel):而所需的输出如下(内置于 Excel):
What argument am I missing in order to make the plot smoother?为了使情节更流畅,我缺少什么论点?
The .csv looks like this: .csv 看起来像这样:
Date,Data
01-09-97,
01-10-97,
01-11-97,
01-12-97,
01-01-98,
01-02-98,
01-03-98,
01-04-98,
01-05-98,309.5
01-06-98,
...
01-07-14,44726.5
01-08-14,45735.1
01-09-14,47430
01-10-14,49887.7
01-11-14,51799.5
01-12-14,54258.1
01-01-15,52079.1
01-02-15,51110.6
01-03-15,49614.8
01-04-15,49989.2
Simple mistake, your date format is not %m-%d-%y
, but %d-%m-%y
:简单的错误,您的日期格式不是%m-%d-%y
,而是%d-%m-%y
:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
# load csv
df=pd.read_csv("test.csv")
# make sure date is in datetime
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%y')
# generate graph
g = sns.lineplot(x="Date", y="Data", data=df)
plt.show()
Output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.