python - 用 Python 绘图 - 甘特图的限制
问题描述
我有一个这样的数据框,它是一个应用程序日志:
+---------+----------------+----------------+---------+----------+-------------------+------------+
| User | ReportingSubId | RecordLockTime | EndTime | Duration | DurationConverted | ActionType |
+---------+----------------+----------------+---------+----------+-------------------+------------+
| User 5 | 21 | 06:19.6 | 06:50.5 | 31 | 00:00:31 | Edit |
| User 4 | 19 | 59:08.6 | 59:27.6 | 19 | 00:00:19 | Add |
| User 25 | 22 | 29:09.4 | 29:37.0 | 28 | 00:00:28 | Edit |
| User 10 | 19 | 28:36.9 | 33:37.0 | 300 | 00:05:00 | Add |
| User 27 | 22 | 13:27.7 | 16:54.9 | 207 | 00:03:27 | Edit |
| User 5 | 21 | 11:22.8 | 12:37.3 | 75 | 00:01:15 | Edit |
+---------+----------------+----------------+---------+----------+-------------------+------------+
我想可视化每个用户添加和编辑的持续时间,甘特图对我来说似乎很理想。
我能够使用以下代码对 807 行的示例数据框执行此操作:
data = []
for row in df_temp.itertuples():
data.append(dict(Task=str(row.User), Start=str(row.RecordLockTime), Finish=str(row.EndTime), Resource=str(row.ActionType)))
colors = {'Add': 'rgb(110, 244, 65)',
'Edit': 'rgb(244, 75, 66)'}
fig = ff.create_gantt(data, colors=colors, index_col='Resource', show_colorbar=True, group_tasks=True)
for i in range(len(fig["data"]) - 2):
text = "User: {}<br>Start: {}<br>Finish: {}<br>Duration: {}<br>Number of Adds: {}<br>Number of Edits: {}".format(df_temp["User"].loc[i],
df_temp["RecordLockTime"].loc[i],
df_temp["EndTime"].loc[i],
df_temp["DurationConverted"].loc[i],
counts[counts["User"] == df_temp["User"].loc[i]]["Add"].iloc[0],
counts[counts["User"] == df_temp["User"].loc[i]]["Edit"].iloc[0])
fig["data"][i].update(text=text, hoverinfo="text")
fig['layout'].update(autosize=True, margin=dict(l=150))
py.iplot(fig, filename='gantt-group-tasks-together', world_readable=True)
我对结果非常满意:https ://plot.ly/~pawelty/90.embed
但是我原来的 df 有更多的用户和总共 2500 行。这似乎对情节来说太过分了。我收到 502 错误。
我是 plotly 的忠实粉丝,但我可能已经达到了它的极限。我可以更改某些内容以使用 Plotly 将其可视化吗?我可以使用其他任何工具吗?
解决方案
我开始使用plotly.offline.plot(fig)
离线绘图,它工作得更快,我得到的错误更少。我也有我的图表没有显示或有时仅在全屏模式下显示的问题......
我导入plotly
而不是plotly.plotly
,否则它不起作用。
推荐阅读
- php - 我处理图片上传的方式安全吗?
- powershell - 替换 csv 中格式错误的时间数据
- plot - 流入散景 varea_stack
- android - 共享元素过渡不适用于按钮文本
- r - 在循环中将所有列表单独转换为数据框
- jwt - LexikJWTAuthenticationBundle 的 JWT 令牌无效
- c# - 如何仅将特定的通用对象传递给方法,该方法将第一个 T 作为派生 T
- python - 用于从 Bokeh 导出 PNG 的带有输出规范的 Crontab 命令
- java - 如何将图像从 picasso 加载到 subsampling-scale-image-view ..请任何人都可以简化这一点?
- python - 如何根据包含的字符串合并两个数据框?