plotly 中的甘特图
Plotly 是一个Python库,用于设计图形,尤其是交互式图形。它可以绘制各种图形和图表,如直方图、条形图、箱线图、散布图等等。它主要用于数据分析和财务分析。 plotly 是一个交互式可视化库。
甘特图
甘特图与描绘项目进度的条形图平行。在甘特图中,纵轴执行任务,横轴执行时间间隔。图表中水平条的宽度显示了两种活动的耐力。甘特图由许多不同的元素组成。主要的 8 个关键组成部分是:
- 任务列表
- 时间线
- 日期线
- 酒吧
- 里程碑
- 依赖项
- 进步
- 分配的资源
Syntax: plotly.figure_factory.create_gantt(df, colors=None, index_col=None, show_colorbar=False, reverse_colors=False, title=’Gantt Chart’, bar_width=0.2, showgrid_x=False, showgrid_y=False, height=600, width=None, tasks=None, task_names=None, data=None, group_tasks=False, show_hover_fill=True)
Parameters:
df: input data for gantt chart. Must be either a a dataframe or a list.
colors: either a plotly scale name, an rgb or hex color, a color tuple or a list of colors
show_colorbar: determines if colorbar will be visible. Only applies if values in the index column are numeric.
show_hover_fill: enables/disables the hovertext for the filled area of the chart.
title: title of the chart
height: Height of the chart
weight: Weight of the chart
示例 1:
Python3
import plotly.figure_factory as ff
df = [dict(Task="A", Start='2020-01-01', Finish='2009-02-02'),
dict(Task="Job B", Start='2020-03-01', Finish='2020-11-11'),
dict(Task="Job C", Start='2020-08-06', Finish='2020-09-21')]
fig = ff.create_gantt(df)
fig.show()
Python3
import plotly.figure_factory as ff
df = [dict(Task="A", Start='2020-01-01', Finish='2009-02-02'),
dict(Task="Job B", Start='2020-03-01', Finish='2020-11-11'),
dict(Task="Job C", Start='2020-08-06', Finish='2020-09-21')]
colors = ['#7a0504', (0.2, 0.7, 0.3), 'rgb(210, 60, 180)']
fig = ff.create_gantt(df, show_colorbar = True, colors = colors )
fig.show()
输出:
示例 2:
Python3
import plotly.figure_factory as ff
df = [dict(Task="A", Start='2020-01-01', Finish='2009-02-02'),
dict(Task="Job B", Start='2020-03-01', Finish='2020-11-11'),
dict(Task="Job C", Start='2020-08-06', Finish='2020-09-21')]
colors = ['#7a0504', (0.2, 0.7, 0.3), 'rgb(210, 60, 180)']
fig = ff.create_gantt(df, show_colorbar = True, colors = colors )
fig.show()
输出: