首页 > 解决方案 > 从情节甘特图中删除基础线(标记)?

问题描述

我正在使用 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')

输出如下所示:

在此处输入图像描述

我想知道,如何从绿色矩形的两侧去除那些白点?或者至少改变它们的颜色?

标签: plotlygantt-chart

解决方案


所以看起来那些白点是“标记”。
因此,使它们透明就足够了。
我决定使用一个循环,以便(将来)能够单独更改每个点的颜色。

在最后一行(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)')

在此处输入图像描述


推荐阅读