问题描述
我有下面的数据框作为我的数据的子集。完整数据集包含周一至周日的“day_of_week”和 24 小时格式的“小时”。
day_of_week hour record
0 Friday 00:00:00 23655
1 Friday 01:00:00 11806
2 Friday 02:00:00 6846
3 Friday 03:00:00 4284
4 Friday 04:00:00 5706
5 Friday 05:00:00 21557
6 Friday 06:00:00 71883
以下是数据类型:
day_of_week category
hour object
record int64
dtype: object
我想创建多个子图,每个 day_of_week 一个图以显示 24 小时内记录的变化。我尝试只在“星期五”先做。
fig = plt.figure()
ax = plt.axes()
ax.plot('hour','record',data = activity_by_hour)
TypeError: float() argument must be a string or a number,not 'datetime.time'
方法二和折线图的制作:
activity_by_hour.loc[activity_by_hour.day_of_week == 'Friday']\
.plot('hour',title = 'Friday',xlabel = "Hour",ylabel = "Ride ('000)",legend = "",linestyle = '--',linewidth = 2)
plt.xticks(ticks = (4 * 60 * 60) * np.arange(6)) # 4 hours interval consists of 14,400 seconds
plt.yticks(ticks = np.arange(0,3.5e5,5e4),labels = [int(num) for num in np.arange(0,5e4)/1000]);
这两种方法有什么区别?如何在显示每天 7 条线的图中绘制周一至周日的类似图表?我尝试了“for 循环”,最终得到了 7 个图表,无论如何,不是一个子图。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)