please see the below image我正在尝试为甘特图创建边框,但遇到以下问题。请在下面查看我的代码,我在显示的图形中收到错误,并且不确定如何继续]
我正在尝试创建到甘特图的边框,但遇到以下问题。请在下面查看我的代码,我在显示的图形中收到错误,并且不确定如何继续]
我正在尝试创建到甘特图的边框,但遇到以下问题。请在下面查看我的代码,我在显示的图形中收到错误,并且不确定如何继续]
import plotly
import plotly.figure_factory as ff
df = [
dict(Task=‘Evening Sleep’, Start=‘2009-01-01’, Finish=‘2009-02-28’, Resource=‘Sleep’, Description = ‘my hover1’ ),
dict(Task=‘Evening Sleep’, Start=‘2009-03-05’, Finish=‘2009-04-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Evening Sleep’, Start=‘2009-04-05’, Finish=‘2009-05-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Evening Sleep’, Start=‘2009-05-05’, Finish=‘2009-06-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-06-05’, Finish=‘2009-07-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-07-05’, Finish=‘2009-08-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-08-05’, Finish=‘2009-09-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-09-05’, Finish=‘2009-10-15’, Resource=‘Cardio’, Description = ‘my hover1’)
]
colors = dict(Cardio = ‘rgb(46, 137, 205)’,
Food = ‘rgb(114, 44, 121)’,
Sleep = ‘rgb(198, 47, 105)’)
fig = ff.create_gantt(df, colors=colors, index_col=‘Resource’, title=‘Daily Schedule’,show_colorbar=True, showgrid_x=True, showgrid_y=True, group_tasks=True)
#fig = ff.create_gantt(df, group_tasks=True)
fig.update_traces(mode=‘lines’, line_color=‘yellow’, selector=dict(fill=‘toself’))
for trace in fig.data:
trace.x += (trace.x[0],)
trace.y += (trace.y[0],)
fig.show()
fig = ff.create_gantt(df, colors=colors, index_col=‘Resource’, title=‘Daily Schedule’,show_colorbar=True, showgrid_x=True, showgrid_y=True, group_tasks=True)
#fig = ff.create_gantt(df, group_tasks=True)enter code here
import plotly
import plotly.figure_factory as ff
df = [
dict(Task=‘Evening Sleep’, Start=‘2009-01-01’, Finish=‘2009-02-28’, Resource=‘Sleep’, Description = ‘my hover1’ ),
dict(Task=‘Evening Sleep’, Start=‘2009-03-05’, Finish=‘2009-04-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Evening Sleep’, Start=‘2009-04-05’, Finish=‘2009-05-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Evening Sleep’, Start=‘2009-05-05’, Finish=‘2009-06-15’, Resource=‘Sleep’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-06-05’, Finish=‘2009-07-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-07-05’, Finish=‘2009-08-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-08-05’, Finish=‘2009-09-15’, Resource=‘Cardio’, Description = ‘my hover1’),
dict(Task=‘Morning Sleep’, Start=‘2009-09-05’, Finish=‘2009-10-15’, Resource=‘Cardio’, Description = ‘my hover1’)
]
colors = dict(Cardio = ‘rgb(46, 137, 205)’,
Food = ‘rgb(114, 44, 121)’,
Sleep = ‘rgb(198, 47, 105)’)
fig = ff.create_gantt(df, colors=colors, index_col=‘Resource’, title=‘Daily Schedule’,show_colorbar=True, showgrid_x=True, showgrid_y=True, group_tasks=True)
#fig = ff.create_gantt(df, group_tasks=True)
fig.update_traces(mode=‘lines’, line_color=‘yellow’, selector=dict(fill=‘toself’))
for trace in fig.data:
trace.x += (trace.x[0],)
trace.y += (trace.y[0],)
fig.show()
fig = ff.create_gantt(df, colors=colors, index_col=‘Resource’, title=‘Daily Schedule’,show_colorbar=True, showgrid_x=True, showgrid_y=True, group_tasks=True)
#fig = ff.create_gantt(df, group_tasks=True)
要在图表上添加边框,请参见here,但总之,您需要这样做:
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
一起,像这样:
import plotly
import plotly.figure_factory as ff
df = [
dict(Task='Evening Sleep', Start='2009-01-01', Finish='2009-02-28', Resource='Sleep', Description = 'my hover1' ),
dict(Task='Evening Sleep', Start='2009-03-05', Finish='2009-04-15', Resource='Sleep', Description = 'my hover1'),
dict(Task='Evening Sleep', Start='2009-04-05', Finish='2009-05-15', Resource='Sleep', Description = 'my hover1'),
dict(Task='Evening Sleep', Start='2009-05-05', Finish='2009-06-15', Resource='Sleep', Description = 'my hover1'),
dict(Task='Morning Sleep', Start='2009-06-05', Finish='2009-07-15', Resource='Cardio', Description = 'my hover1'),
dict(Task='Morning Sleep', Start='2009-07-05', Finish='2009-08-15', Resource='Cardio', Description = 'my hover1'),
dict(Task='Morning Sleep', Start='2009-08-05', Finish='2009-09-15', Resource='Cardio', Description = 'my hover1'),
dict(Task='Morning Sleep', Start='2009-09-05', Finish='2009-10-15', Resource='Cardio', Description = 'my hover1')
]
colors = dict(Cardio = 'rgb(46, 137, 205)',
Food = 'rgb(114, 44, 121)',
Sleep = 'rgb(198, 47, 105)')
fig = ff.create_gantt(df, colors=colors,
index_col='Resource',
title='Daily Schedule',
show_colorbar=True,
showgrid_x=True,
showgrid_y=True,
group_tasks=True)
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.show()