使用pythonplotly绘制甘特图

问题描述 投票:0回答:1

enter image description here这是我使用 Python Plotly 创建甘特图的代码。我需要用独特的颜色掩盖所有的叶子或假期。

我期待这样的图像

df = pd.read_excel('Project Priority List.xlsx')df.columns = df.iloc[0]

#Remove the first row, which is now the header
df = df[1:]
#Optionally, reset the index
df.reset_index(drop=True, inplace=True)
Modelling = {'Oscar','Parvathy Anil','Pavan','Puru','Senthil','Vel','Vetrivel','Subramanian'}MO = {'Anju','Naveen','Parvathy M','Shaima','Manikandan','Saranya'}


Modelling_Team = df[df['WnS POC'].isin(Modelling)]MO_Team = df[df['WnS POC'].isin(MO)]Modelling_Team.reset_index(drop=True, inplace=True)MO_Team.reset_index(drop=True, inplace=True)

filter_condition = Modelling_Team['Active Task'].str.contains('Active|Leave', case=False, na=False)
#Apply the filter condition to the DataFrame
dff = Modelling_Team[filter_condition]
fig = px.timeline(dff, x_start='Start Date', x_end='Planned Due Date', y='Project (Scope)', color='WnS POC', title='Gantt Chart', hover_data=['Project Name', 'Priority'])
#Configure the Gantt chart layout
#fig.update_yaxes(categoryorder='total ascending')fig.update_xaxes(title_text='Timeline')

#Enable zooming and panning for detailed viewing
fig.update_xaxes(rangeslider_visible=True)fig.update_yaxes(autorange="reversed")fig.update_layout(xaxis=dict(type="date"))
#Show the Gantt chart
fig.show()
pio.write_html(fig, file='timeline_center image description herehart.html')
python python-3.x plotly plotly-dash gantt-chart
1个回答
0
投票

这是我为我的问题找到的答案

fig.add_trace(
px.timeline(leave_df, x_start='Start Date', x_end='Planned Due Date', y='Project (Scope)').update_traces(marker=dict(color='black')).data[0]

© www.soinside.com 2019 - 2024. All rights reserved.