1 回答

TA貢獻1796條經驗 獲得超7個贊
嘗試這個:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as md
import matplotlib.dates as mdates
import datetime as dt
data = {"Date":['2019-2-25 14:24:04', '2019-2-25 14:29:02', '2019-2-20 17:02:14',
'2019-3-25 08:12:54', '2019-3-25 12:32:32'],
"Quiz":[1,2,2,3,4],
"Score":[10,3,7,4,9]}
df = pd.DataFrame.from_dict(data)
xs = df.Date.values
fig, ax = plt.subplots(1)
ax.set_xlabel("Date")
ax.set_ylabel("Score")
ax.plot_date(xs, df.Score)
fig.autofmt_xdate(rotation=45)
plt.show()
主要區別是刪除格式化業務并設置 xs = df.Date.values,然后讓圖表自己處理格式化fig.autofmt_xdate(rotation=45)。
添加回答
舉報