@@ -1897,10 +1897,19 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
1897
1897
used for indexing. If a list, its elements must be dictionaries
1898
1898
with the same required column headers: 'Task', 'Start' and
1899
1899
'Finish'.
1900
- :param (str|list|dict) colors: a list of 'rgb(a, b, c)' colors where a, b and c
1901
- are between 0 and 255. Can also be a Plotly colorscale but this is
1902
- will result in only a 2-color cycle. If number of colors is less
1903
- than the total number of tasks, colors will cycle
1900
+ :param (str|list|dict) colors: either a plotly scale name, an rgb
1901
+ or hex color, a color tuple or a list of colors. An rgb color is
1902
+ of the form 'rgb(x, y, z)' where x, y, z belong to the interval
1903
+ [0, 255] and a color tuple is a tuple of the form (a, b, c) where
1904
+ a, b and c belong to [0, 1]. If colors is a list, it must
1905
+ contain the valid color types aforementioned as its members.
1906
+ If a dictionary, all values of the indexing column must be keys in
1907
+ colors.
1908
+ :param (str|float) index_col: the column header (if df is a data
1909
+ frame) that will function as the indexing column. If df is a list,
1910
+ index_col must be one of the keys in all the items of df.
1911
+ :param (bool) show_colorbar: determines if colorbar will be visible.
1912
+ Only applies if values in the index column are numeric.
1904
1913
:param (bool) reverse_colors: reverses the order of selected colors
1905
1914
:param (str) title: the title of the chart
1906
1915
:param (float) bar_width: the width of the horizontal bars in the plot
@@ -1923,10 +1932,10 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
1923
1932
fig = FF.create_gantt(df)
1924
1933
1925
1934
# Plot the data
1926
- py.iplot(fig, filename='Gantt Chart', world_readable=True)
1935
+ py.iplot(fig, filename='Simple Gantt Chart', world_readable=True)
1927
1936
```
1928
1937
1929
- Example 2: Colormap by 'Complete' Variable
1938
+ Example 2: Index by Column with Numerical Entries
1930
1939
```
1931
1940
import plotly.plotly as py
1932
1941
from plotly.tools import FigureFactory as FF
@@ -1940,11 +1949,61 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
1940
1949
Finish='2009-05-30', Complete=95)]
1941
1950
1942
1951
# Create a figure with Plotly colorscale
1943
- fig = FF.create_gantt(df, colors='Blues',
1944
- bar_width=0.5, showgrid_x=True, showgrid_y=True)
1952
+ fig = FF.create_gantt(df, colors='Blues', index_col='Complete',
1953
+ show_colorbar=True, bar_width=0.5,
1954
+ showgrid_x=True, showgrid_y=True)
1945
1955
1946
1956
# Plot the data
1947
- py.iplot(fig, filename='Colormap Gantt Chart', world_readable=True)
1957
+ py.iplot(fig, filename='Numerical Entries', world_readable=True)
1958
+ ```
1959
+
1960
+ Example 3: Index by Column with String Entries
1961
+ ```
1962
+ import plotly.plotly as py
1963
+ from plotly.tools import FigureFactory as FF
1964
+
1965
+ # Make data for chart
1966
+ df = [dict(Task="Job A", Start='2009-01-01',
1967
+ Finish='2009-02-30', Resource='Apple'),
1968
+ dict(Task="Job B", Start='2009-03-05',
1969
+ Finish='2009-04-15', Resource='Grape'),
1970
+ dict(Task="Job C", Start='2009-02-20',
1971
+ Finish='2009-05-30', Resource='Banana')]
1972
+
1973
+ # Create a figure with Plotly colorscale
1974
+ fig = FF.create_gantt(df, colors=['rgb(200, 50, 25)',
1975
+ (1, 0, 1),
1976
+ '#6c4774'],
1977
+ index_col='Resource',
1978
+ reverse_colors=True)
1979
+
1980
+ # Plot the data
1981
+ py.iplot(fig, filename='String Entries', world_readable=True)
1982
+ ```
1983
+
1984
+ Example 4: Use a dictionary for colors
1985
+ ```
1986
+ import plotly.plotly as py
1987
+ from plotly.tools import FigureFactory as FF
1988
+
1989
+ # Make data for chart
1990
+ df = [dict(Task="Job A", Start='2009-01-01',
1991
+ Finish='2009-02-30', Resource='Apple'),
1992
+ dict(Task="Job B", Start='2009-03-05',
1993
+ Finish='2009-04-15', Resource='Grape'),
1994
+ dict(Task="Job C", Start='2009-02-20',
1995
+ Finish='2009-05-30', Resource='Banana')]
1996
+
1997
+ # Make a dictionary of colors
1998
+ colors = {'Apple': 'rgb(255, 0, 0)',
1999
+ 'Grape': 'rgb(170, 14, 200)',
2000
+ 'Banana': (1, 1, 0.2)}
2001
+
2002
+ # Create a figure with Plotly colorscale
2003
+ fig = FF.create_gantt(df, colors=colors, index_col='Resource')
2004
+
2005
+ # Plot the data
2006
+ py.iplot(fig, filename='dictioanry colors', world_readable=True)
1948
2007
```
1949
2008
"""
1950
2009
plotly_scales = {'Greys' : ['rgb(0,0,0)' , 'rgb(255,255,255)' ],
@@ -2115,10 +2174,17 @@ def create_gantt(df, colors=None, index_col=None, show_colorbar=False,
2115
2174
colors .reverse ()
2116
2175
2117
2176
if not index_col :
2118
- fig = FigureFactory ._gantt (chart , colors , title ,
2119
- bar_width , showgrid_x , showgrid_y ,
2120
- height , width , tasks = None ,
2121
- task_names = None , data = None )
2177
+ if isinstance (colors , dict ):
2178
+ raise exceptions .PlotlyError ("Error. You have set colors to "
2179
+ "a dictionary but have not "
2180
+ "picked an index. An index is "
2181
+ "required if you are assigning "
2182
+ "colors to particular values "
2183
+ "in a dictioanry." )
2184
+
2185
+ fig = FigureFactory ._gantt (chart , colors , title , bar_width ,
2186
+ showgrid_x , showgrid_y , height , width ,
2187
+ tasks = None , task_names = None , data = None )
2122
2188
return fig
2123
2189
2124
2190
else :
0 commit comments