简体   繁体   中英

Seaborn: lineplot looks like a step plot

I'm trying to build a line plot with Seaborn in Jupyter Notebook, using the code below:

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): 在此处输入图片说明

What argument am I missing in order to make the plot smoother?

The .csv looks like this:

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 :

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:

在此处输入图片说明

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