绘制 pandas 时间线中的时间段 [英] Plot time periods in timeline from pandas

查看:53
本文介绍了绘制 pandas 时间线中的时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否可以通过 Anaconda 发行版中的 matplotlib 或其他可视化工具实现.

我知道如何用 JavaScript 做到这一点,并且可能会走这条路,但我想看看是否有办法在我的 Jupyter 笔记本中做到这一点.我有多个时间段,我想绘制的每一行数据都有一个开始和结束日期时间.我的目标实际上是找到任何行中没有时间段的差距.

这是一个例子:

编辑

要将任务组合在一起,请使用 -

fig = ff.create_gantt(df_full, group_tasks=True)py.iplot(fig, filename='gantt-group-tasks-together', world_readable=True)

I don't know if this is possible to do with matplotlib or other visualization tools in Anaconda distribution.

I know how to do this with JavaScript and may just go that route, but figured I'd see if there is a way to do it in my Jupyter notebook. I have multiple time periods with a start and end datetime for each row of data I want to plot. My goal is actually to find gaps where there is no time period in any row.

Here is an example: http://visjs.org/examples/timeline/other/groupsPerformance.html

All rows have at least one time period, but some have multiple periods. Is there a way to do this in matplotlib or seaborn?

A pointer to specific documentation for this kind of visualization or an example is sufficient.

Sample dataframe:

    id           start1        end1      start2        end2
0  Bob       2018-11-29  2018-11-30  2018-12-01  2018-12-31
1  James     2018-10-19  2018-10-31         NaT         NaT
2  Jane      2018-04-05  2018-07-12  2018-11-29  2018-11-30

So the Y-axis would contain the id field, and X-axis would be the time. Each row would have (broken) horizontal bars for each , where applicable (there may or may not be a second period).

解决方案

If you are open to using plotly, this can take you closer -

df_full = df[['id','start1','end1']].rename(columns={'id':'Task','start1':'Start','end1':'Finish'}).append(
    df[['id','start2','end2']].rename(columns={'id':'Task','start2':'Start','end2':'Finish'}),sort=False).reset_index()

import plotly.plotly as py
import plotly.figure_factory as ff

fig = ff.create_gantt(df_full)
py.iplot(fig, filename='gantt-simple-gantt-chart', world_readable=True)

EDIT

To group tasks together, use -

fig = ff.create_gantt(df_full, group_tasks=True)
py.iplot(fig, filename='gantt-group-tasks-together', world_readable=True)

这篇关于绘制 pandas 时间线中的时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆