plotly - 从情节甘特图中删除基础线(标记)?
问题描述
我正在使用 Plotly 绘制一个大型甘特图。
这些是输入数据(“test.data”)的几个留置权:
1493194324 2017-04-26 10:12:04 A 1493195658 2017-04-26 10:34:18
1493196858 2017-04-26 10:54:18 B 1493197661 2017-04-26 11:07:41
1493200062 2017-04-26 11:47:42 C 1493202312 2017-04-26 12:25:12
1493202912 2017-04-26 12:35:12 A 1493206109 2017-04-26 13:28:29
1493207309 2017-04-26 13:48:29 B 1493208470 2017-04-26 14:07:50
1493210270 2017-04-26 14:37:50 A 1493212328 2017-04-26 15:12:08
1493213529 2017-04-26 15:32:09 B 1493214283 2017-04-26 15:44:43
1493270086 2017-04-27 07:14:46 C 1493270988 2017-04-27 07:29:48
1493275788 2017-04-27 08:49:48 A 1493276767 2017-04-27 09:06:07
1493278683 2017-04-27 09:38:03 A 1493279943 2017-04-27 09:59:03
1493280543 2017-04-27 10:09:03 C 1493281660 2017-04-27 10:27:40
1493284060 2017-04-27 11:07:40 B 1493285028 2017-04-27 11:23:48
我使用此代码绘制甘特图:
import plotly.offline as offline
import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.graph_objs as go
import plotly.io as pio
import pandas as pd
import numpy as np
filePath="test.data"
df = pd.read_table(filePath,
header=None,
usecols=[1,2, 4],
sep='\t',
converters={1:np.datetime64, 3:np.datetime64},
)
df.columns = ['Start','Task', 'Finish']
df['Resource'] = 'Done'
colors = {'Done': 'rgb(0, 240, 0)',}
fig = ff.create_gantt(df,
title='My Tasks',
bar_width=0.1,
showgrid_x=False,
showgrid_y=False,
colors=colors,
index_col='Resource',
show_colorbar = True,
group_tasks=True,
)
fig['layout'].update(plot_bgcolor = 'rgba(0,0,0,250)',
paper_bgcolor = 'rgba(0,0,0,0)',
showlegend = True,
)
offline.plot(fig, image = 'png', image_filename='test', output_type='file', image_width=500, image_height=500, filename='test.html')
输出如下所示:
我想知道,如何从绿色矩形的两侧去除那些白点?或者至少改变它们的颜色?
解决方案
所以看起来那些白点是“标记”。
因此,使它们透明就足够了。
我决定使用一个循环,以便(将来)能够单独更改每个点的颜色。
在最后一行(offline.plot...)之前添加此代码可以解决问题。
marker = dict(color = 'rgba(0, 0, 0, 0)')
for i in fig['data']:
i.update(marker = marker)
此外
,做相反的事情可能会有用!
这意味着保留标记并删除矩形。
在这种情况下,我们可以通过将bar_width设置为 0 来隐藏矩形:
bar_width=0.0
并为标记添加颜色:
marker = dict(color = 'rgba(255, 255, 255, 255)')
推荐阅读
- javascript - Postgres UPDATE 插入值而不是所有列
- asp.net-core - odata 和非 odata 路由能否共同存在
- java - JDBC 模板是否缓存连接?
- terraform - Terraform - 为什么这不会导致循环依赖?
- c++ - Visual Studio Code 异常缓慢
- typescript - TypeScript 中 DOM 元素的类型问题
- c# - 无法在 lambda 表达式中转换类型错误的对象 (CsvHelper)
- c++ - 无法理解此 return 语句的功能,没有它会发生运行时错误
- php - Laravel文件上传不更改名称
- python - 连接 Flask Socket.IO 服务器和 Flutter