事件数据的直方图
我有以下数据:
start_time end_time duration ic_total mc_total
0 2022-01-01 10:00:00 2022-01-01 19:00:00 9.0 0.0 1.7780003947160878
1 2022-01-02 00:00:00 2022-01-02 10:00:00 10.0 0.0 0.0
2 2022-01-02 17:00:00 2022-01-03 02:00:00 9.0 0.7620001691640255 1.7780003947160594
3 2022-01-03 02:00:00 2022-01-04 12:00:00 34.0 3.810000845820184 4.31800095859623
4 2022-01-07 21:00:00 2022-01-08 06:00:00 9.0 10.287002283714486 1.016000225552034
5 2022-01-16 05:00:00 2022-01-16 20:00:00 15.0 0.0 0.0
6 2022-01-19 04:00:00 2022-01-19 17:00:00 13.0 2.286000507492133 0.5926667982386957
7 2022-01-21 14:00:00 2022-01-22 00:00:00 10.0 1.7780003947160736 0.0
8 2022-01-27 02:00:00 2022-01-27 16:00:00 14.0 14.986003326892735 9.588502128647471
在数据框中。
如何产生一个带有持续时间列定义宽度的条的图,而由IC_Total值定义的宽度?以及X轴上的位置是由开始和结束时间定义的?
感谢 riley ,我现在可以根据需要绘制数据的数据,但是遇到了另一个问题! 我在单独的数据范围中也有类似的数据,并希望将它们绘制在同一图上。我有以下代码:
_, ax = plt.subplots(sharex=False)
sc.Stairs(bdf, "start_time", "end_time", "ic_total").plot(ax,label='Bresser\open')
sc.Stairs(frdf, "start_time", "end_time", "ic_total").plot(ax, label='FR Gauge')
sc.Stairs(hpdf, "start_time", "end_time", "ic_total").plot(ax, label='Highpoint')
如果我运行代码,则在屏幕截图中生成右下角的绘图。(图4)。单独运行每条线将成功生成楼梯图(图1-3)。 我尝试过sharex = false毫无喜悦。我猜想有某种冲突X轴,是否有可能用自己的轴绘制每条线的绘制,这会解决问题吗?
第二次编辑:
在进一步调查中,似乎原始答案毕竟不起作用。条形的宽度应由“持续时间”列定义的宽度,这是“ start_time”和“ end_time”之间的小时时间,这是否是直方图问题?
I have the following data:
start_time end_time duration ic_total mc_total
0 2022-01-01 10:00:00 2022-01-01 19:00:00 9.0 0.0 1.7780003947160878
1 2022-01-02 00:00:00 2022-01-02 10:00:00 10.0 0.0 0.0
2 2022-01-02 17:00:00 2022-01-03 02:00:00 9.0 0.7620001691640255 1.7780003947160594
3 2022-01-03 02:00:00 2022-01-04 12:00:00 34.0 3.810000845820184 4.31800095859623
4 2022-01-07 21:00:00 2022-01-08 06:00:00 9.0 10.287002283714486 1.016000225552034
5 2022-01-16 05:00:00 2022-01-16 20:00:00 15.0 0.0 0.0
6 2022-01-19 04:00:00 2022-01-19 17:00:00 13.0 2.286000507492133 0.5926667982386957
7 2022-01-21 14:00:00 2022-01-22 00:00:00 10.0 1.7780003947160736 0.0
8 2022-01-27 02:00:00 2022-01-27 16:00:00 14.0 14.986003326892735 9.588502128647471
in a dataframe.
How can I produce a plot with bars whose width are defined by the duration column, and height by the ic_total value?, and whos position on the x axis is defined by the start and end time?
Thanks to the answer from Riley, I can now plot the data as desired, but have run into a further problem!
I have similar data in seperate dataframes, and want to plot them on the same plot. i have the following code:
_, ax = plt.subplots(sharex=False)
sc.Stairs(bdf, "start_time", "end_time", "ic_total").plot(ax,label='Bresser\open')
sc.Stairs(frdf, "start_time", "end_time", "ic_total").plot(ax, label='FR Gauge')
sc.Stairs(hpdf, "start_time", "end_time", "ic_total").plot(ax, label='Highpoint')
If I run the code it generates the plot bottom right in screenshot.(figure 4). Running each line individually generates the staircase plot successfully (figures 1-3).
I've tried sharex=False with no joy. I'm guessing that there is some sort of conflict wityh the x axis, is it possible toi plot each line with it's own axis and will this solve the issue?
Second edit:
on further investigation it seems that the original answer doesn't work after all. The bars should have a width defined by the 'duration' column, which is the time in hours between 'start_time' and 'end_time', is this more of a histogram question?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像是我对我来说是一个步骤功能图,您可以使用
staircase
熊猫生态系统的一部分。假设您的dataframe称为
df
以下几乎没有努力Sounds like a step function plot to me, for which you can use
staircase
, which operates as part of the pandas ecosystem.Assuming your dataframe is called
df
the following will produce a plot with little effortnote: I am the creator of staircase. Please feel free to reach out with feedback or questions if you have any.
我已经成功解决了这个问题,我的答案,详细说明了所使用的方法在这里。
马特·库珀的回答
I have managed to solve this problem, my answer, detailing the method used is here.
Matt Cooper's answer