반응형
plotly.figure_factory
.create_gantt
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)¶
deprecated, use instead plotly.express.timeline()
.
Returns figure for a gantt chart
Parameters
- df ((arraylist)) – input data for gantt chart. Must be either a a dataframe or a list. If dataframe, the columns must include ‘Task’, ‘Start’ and ‘Finish’. Other columns can be included and used for indexing. If a list, its elements must be dictionaries with the same required column headers: ‘Task’, ‘Start’ and ‘Finish’.
- colors ((strlistdicttuple)) – either a plotly scale name, an rgb or hex color, a color tuple or a list of colors. An rgb color is of the form ‘rgb(x, y, z)’ where x, y, z belong to the interval [0, 255] and a color tuple is a tuple of the form (a, b, c) where a, b and c belong to [0, 1]. If colors is a list, it must contain the valid color types aforementioned as its members. If a dictionary, all values of the indexing column must be keys in colors.
- index_col ((strfloat)) – the column header (if df is a data frame) that will function as the indexing column. If df is a list, index_col must be one of the keys in all the items of df.
- show_colorbar ((bool)) – determines if colorbar will be visible. Only applies if values in the index column are numeric.
- show_hover_fill ((bool)) – enables/disables the hovertext for the filled area of the chart.
- reverse_colors ((bool)) – reverses the order of selected colors
- title ((str)) – the title of the chart
- bar_width ((float)) – the width of the horizontal bars in the plot
- showgrid_x ((bool)) – show/hide the x-axis grid
- showgrid_y ((bool)) – show/hide the y-axis grid
- height ((float)) – the height of the chart
- width ((float)) – the width of the chart
Example 1: Simple Gantt Chart
>>> from plotly.figure_factory import create_gantt
>>> # Make data for chart
>>> df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-30'),
... dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
... dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')]
>>> # Create a figure
>>> fig = create_gantt(df)
>>> fig.show()
Example 2: Index by Column with Numerical Entries
>>> from plotly.figure_factory import create_gantt
>>> # Make data for chart
>>> df = [dict(Task="Job A", Start='2009-01-01',
... Finish='2009-02-30', Complete=10),
... dict(Task="Job B", Start='2009-03-05',
... Finish='2009-04-15', Complete=60),
... dict(Task="Job C", Start='2009-02-20',
... Finish='2009-05-30', Complete=95)]
>>> # Create a figure with Plotly colorscale
>>> fig = create_gantt(df, colors='Blues', index_col='Complete',
... show_colorbar=True, bar_width=0.5,
... showgrid_x=True, showgrid_y=True)
>>> fig.show()
Example 3: Index by Column with String Entries
>>> from plotly.figure_factory import create_gantt
>>> # Make data for chart
>>> df = [dict(Task="Job A", Start='2009-01-01',
... Finish='2009-02-30', Resource='Apple'),
... dict(Task="Job B", Start='2009-03-05',
... Finish='2009-04-15', Resource='Grape'),
... dict(Task="Job C", Start='2009-02-20',
... Finish='2009-05-30', Resource='Banana')]
>>> # Create a figure with Plotly colorscale
>>> fig = create_gantt(df, colors=['rgb(200, 50, 25)', (1, 0, 1), '#6c4774'],
... index_col='Resource', reverse_colors=True,
... show_colorbar=True)
>>> fig.show()
Example 4: Use a dictionary for colors
>>> from plotly.figure_factory import create_gantt
>>> # Make data for chart
>>> df = [dict(Task="Job A", Start='2009-01-01',
... Finish='2009-02-30', Resource='Apple'),
... dict(Task="Job B", Start='2009-03-05',
... Finish='2009-04-15', Resource='Grape'),
... dict(Task="Job C", Start='2009-02-20',
... Finish='2009-05-30', Resource='Banana')]
>>> # Make a dictionary of colors
>>> colors = {'Apple': 'rgb(255, 0, 0)',
... 'Grape': 'rgb(170, 14, 200)',
... 'Banana': (1, 1, 0.2)}
>>> # Create a figure with Plotly colorscale
>>> fig = create_gantt(df, colors=colors, index_col='Resource',
... show_colorbar=True)
>>> fig.show()
Example 5: Use a pandas dataframe
>>> from plotly.figure_factory import create_gantt
>>> import pandas as pd
>>> # Make data as a dataframe
>>> df = pd.DataFrame([['Run', '2010-01-01', '2011-02-02', 10],
... ['Fast', '2011-01-01', '2012-06-05', 55],
... ['Eat', '2012-01-05', '2013-07-05', 94]],
... columns=['Task', 'Start', 'Finish', 'Complete'])
>>> # Create a figure with Plotly colorscale
>>> fig = create_gantt(df, colors='Blues', index_col='Complete',
... show_colorbar=True, bar_width=0.5,
... showgrid_x=True, showgrid_y=True)
>>> fig.show()
Additional Example
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
fig.show()
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Resource="Alex"),
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', Resource="Alex"),
dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Resource="Max")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Resource")
fig.update_yaxes(autorange="reversed")
fig.show()
df = [dict(Task="Job-1", Start='2017-01-01', Finish='2017-02-02', Resource='Complete'),
dict(Task="Job-1", Start='2017-02-15', Finish='2017-03-15', Resource='Incomplete'),
dict(Task="Job-2", Start='2017-01-17', Finish='2017-02-17', Resource='Not Started'),
dict(Task="Job-2", Start='2017-01-17', Finish='2017-02-17', Resource='Complete'),
dict(Task="Job-3", Start='2017-03-10', Finish='2017-03-20', Resource='Not Started'),
dict(Task="Job-3", Start='2017-04-01', Finish='2017-04-20', Resource='Not Started'),
dict(Task="Job-3", Start='2017-05-18', Finish='2017-06-18', Resource='Not Started'),
dict(Task="Job-4", Start='2017-01-14', Finish='2017-03-14', Resource='Complete')]
colors = {'Not Started': 'rgb(220, 0, 0)',
'Incomplete': (1, 0.9, 0.16),
'Complete': 'rgb(0, 255, 100)'}
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True,
group_tasks=True)
fig.show()
반응형
'학부공부 > OS_운영체제' 카테고리의 다른 글
TP1.6. Corner case [OS Scheduling simulator] (2) | 2022.06.06 |
---|---|
TP1.5. File format for Evaluation module [OS Scheduling simulator] (2) | 2022.06.06 |
TP1.3. 05.20. BREAKOUT MEETING [OS Scheduling simulator] (2) | 2022.06.06 |
TP1.2. Git branch [OS Scheduling simulator] (0) | 2022.06.06 |
TP1.1. 05.13.BREAKOUT MEETING [OS Scheduling simulator] (2) | 2022.06.06 |
댓글