【问题标题】:How do I plot excel time format with matplot?如何使用 matplot 绘制 excel 时间格式?
【发布时间】:2022-12-03 17:22:08
【问题描述】:

I am trying to plot Formula 1 laptimes with matplotlib. I want the Y axis to show the laptimes, while the Xaxis shows the iD number of the race the laptimes belong to. The time is from a CSV file and the cell contains a date format, e.g., 01:22.0 reads as 12:01:24AM on the excel cell.

`

       raceId      time  milliseconds
6079      100  1:18.739         78739    
4438       81  1:20.502         80502   
63          8  1:20.735         80735   
3517       60  1:21.599         81599    
7280      118  1:22.236         82236   
8065      133  1:23.083         83083  
9018      151  1:23.405         83405 
13205     215  1:24.475         84475   

`

Tried using pd.to_datetime(df[\'time]). Graph was showing the dates only, no time. How do i plot the time against the raceId?

mpl_values = pd.to_datetime(df[\'time\'])
plt.plot(df[\'raceId\'],mpl_values,marker = \'.\', markersize = 10)
plt.xlabel(\'raceId\')
plt.ylabel(\'Laptimes\')
plt.show()
  • Did you try from matplotlib.dates import date2num, mpl_values = date2num(excel_values)?
  • mpl_values = date2num(excel_values) I did this, passing df[\'time] into excel_values, and i got an error ValueError: Error parsing datetime string \"1:29.288\" at position 1

标签: python pandas matplotlib jupyter-notebook


【解决方案1】:
猜你喜欢
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多