如何使用matplotlib获得甘特图

时间:2017-04-12 10:59:35

标签: python matplotlib gantt-chart

我收到了很多数据:

a0:86:c6:52:4e:e8,0.006568,0.006620,Out
a0:86:c6:52:4e:e8,0.006663,0.006695,In
a0:86:c6:52:4e:e8,0.008089,0.008141,Out
a0:86:c6:52:4e:e8,0.008185,0.008217,In
01:00:5e:00:00:fb,0.033096,0.035016,Out
33:33:00:00:00:fb,0.034997,0.037077,Out
01:00:5e:7f:ff:fa,0.039969,0.042057,Out
ff:ff:ff:ff:ff:ff,0.059823,0.061639,Out
a0:86:c6:52:4e:e8,0.068865,0.068917,Out
a0:86:c6:52:4e:e8,0.068962,0.068994,In
a0:86:c6:52:4e:e8,0.083492,0.083544,Out
a0:86:c6:52:4e:e8,0.083588,0.083620,In
...

实际上,持续120秒。我想用matplotlib将这些数据绘制成甘特图。 原因是大多数甘特图api仅支持时间格式YY-MM-DD HH:MM:SS,而不是如此小(微秒)大小。

请告诉我怎么做?

1 个答案:

答案 0 :(得分:15)

为了在matplotlib中生成甘特图,可以使用plt.broken_barh函数。 matplotlib页面上有a broken_barh example

为了过滤和分组数据,可以使用pandas,尤其是数据帧的jenkins@jenkins:~$ alias alias l='ls -lAh' alias rvm-restart='rvm_reload_flag=1 source '\''/Users/jenkins/.rvm/scripts/rvm'\''' 函数。

这是一个完整的例子:

groupby

产生以下图:

enter image description here