我试图将我的步骤绘制为散点图,然后最终添加一条趋势线。我设法让它与 df.plot() 一起使用,但它是一个折线图。以下是我尝试过的代码:import pandas as pdimport matplotlib.pyplot as pltimport numpy as npdata_file = pd.read_csv('CSV/stepsgyro.csv')# print(data_file.head())# put in the correct data typesdata_file = data_file.astype({"steps": int})pd.to_datetime(data_file['date'])# makes the date definitely the index at the bottomdata_file.set_index(['date'], inplace=True)# sorts the data frame by the indexdata_file.sort_values(by=['date'], inplace=True, ascending=True)# data_file.columns.values[1] = 'date'# plot the raw steps data# data_file.plot()plt.scatter(data_file.date, data_file.steps)plt.title('Daily Steps')plt.grid(alpha=0.3)plt.show()plt.close('all')# plot the cumulative steps datadata_file = data_file.cumsum()data_file.plot()plt.title('Cumulative Daily Steps')plt.grid(alpha=0.3)plt.show()plt.close('all')这是它在我的 IDE 上的样子的屏幕截图:
添加回答
举报
0/150
提交
取消