【发布时间】:2019-03-10 15:34:37
【问题描述】:
我在这里有一个数据框,其中有两个独特的时间窗口,分别位于 df_mo4['time_window']、2018-09-26 11:30:00 到 2018-09-26 11:32:30 和 2018-09-26 11:32:30 到 2018-09-26 11:35:00。我想绘制 2 组条形图(不是子图),其中第一个条形图描绘了一个时间窗口中单个 ID 的平均值、最大和最小时间,下一个条形图描绘了另一个时间窗口中的相同数据,如何我能做些什么吗?另外,我希望标题类似于 Duration (time_window)。谢谢!
df.plot(kind='bar')
plt.title('Duration \n {}'.format(df['time_window']))
plt.ylabel('Time (s)')
plt.xlabel('ID')
plt.legend(['Mean Time (s)', 'Minimum Time (s)', 'Maximum Time (s)'], loc='upper right')
plt.xticks(np.arange(len(df['ID'])), df['ID'], fontsize=5)
plt.show()
样本数据:
ID time_window mean_time min_time max_time
0 8027 2018-09-26 11:30:00 to 2018-09-26 11:32:30 0.101679 0.056412 0.340988
1 8027 2018-09-26 11:32:30 to 2018-09-26 11:35:00 0.090957 0.052196 0.323442
2 8028 2018-09-26 11:30:00 to 2018-09-26 11:32:30 0.199167 0.076872 0.614797
3 8028 2018-09-26 11:32:30 to 2018-09-26 11:35:00 0.239885 0.062660 0.590710
4 8029 2018-09-26 11:30:00 to 2018-09-26 11:32:30 0.243241 0.098516 0.5713
5 8030 2018-09-26 11:30:00 to 2018-09-26 11:32:30 0.083064 0.055656 0.27892
6 8031 2018-09-26 11:32:30 to 2018-09-26 11:35:00 0.134786 0.058290 0.51279
【问题讨论】:
标签: python dataframe matplotlib unique