简体   繁体   English

条形 plot 与 x 轴上的时间

[英]bar plot with time on x axis

I have a pandas dataframe (filtered_4_6) from which i extract the occurance of event on an hourly basis with the following code:我有一个 pandas dataframe (filtered_4_6) ,我使用以下代码每小时从中提取事件的发生:

Filtered_time = filtered_4_6['Date'].dt.time.value_counts()

this gives me 24 rows with time in the first column and number of event on the second.这给了我 24 行,第一列有时间,第二列有事件数。 i want to bar plot these 24 bars but can't seem to find how to use the time column as x axis我想把 plot 这 24 条条形,但似乎找不到如何将时间列用作 x 轴

the result looks like this:结果如下所示:

在此处输入图像描述

i've tried different ideas but none works:我尝试了不同的想法,但没有一个可行:

plt.bar(Filtered_time.index, Filtered_time.values)

it is certainly a format conversion error, but i can't figure it out.这肯定是格式转换错误,但我无法弄清楚。

i've tried to make Filtered_time a dataframe我试图让 Filtered_time 成为 dataframe

Filtered_time = pd.DataFrame(filtered_4_6['Date'].dt.time.value_counts())

but still get an error但仍然出现错误

TypeError: the dtypes of parameters x (object) and width (float64) are incompatible TypeError:参数x(object)和width(float64)的dtypes不兼容

Try plotting with the strings instead:尝试使用字符串进行绘图:

filtered_time = filtered_4_6['Date'].dt.strftime('%H:%M:%S').value_counts()
filtered_time.plot()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM