如何更改图例栏和颜色以单独显示 Dataframe 中的每一行? (据index_col)
How to change the legend bar and colors to show each row in Dataframe individually? (Accdg to index_col)
如何更改图例栏和颜色以单独显示 Dataframe 中的每一行?我当前的图表如下所示:
代码如下:
def chart(task_list, filename):
fig = ff.create_gantt(task_list, colors='Rainbow', index_col='Resource', show_colorbar=True, group_tasks=True)
# plot(fig, filename=filename)
return plot(fig, filename=filename, include_plotlyjs=False, output_type='div')
#print(fig)
'Rainbow' 是默认的 plotly 色标。但是,如果我没记错的话,它仅限于两种颜色。
我只希望图表有一个类似于此的图例(无论是点还是线,只是不是像当前甘特图那样的渐变条):
代码如下:
df = [dict(Task="Job A", Start='2016-01-01', Finish='2016-01-02', Resource='Apple'),
dict(Task="Job B", Start='2016-01-02', Finish='2016-01-04', Resource='Grape'),
dict(Task="Job C", Start='2016-01-02', Finish='2016-01-03', Resource='Banana')]
colors = dict(Apple = 'rgb(220, 0, 0)',
Grape = 'rgb(170, 14, 200)',
Banana = (1, 0.9, 0.16))
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True)
py.iplot(fig, filename='gantt-dictioanry-colors', world_readable=True)
但是,当我使用文档中的代码时,它只有有限数量的颜色,由字典 colors 设置。我希望颜色能够在 Dataframe 中有新行时自行生成。
TLDR;需要一个 COLORSCALE 能够容纳 Dataframe 中不断增加的行数,并将渐变条更改为 lines/dots/whatever 以根据 index_col.
作为每个 Dataframe 行的图例
试试这个
在将 Resource
传递给 def chart(task_list, filename)
之前将其更改为字符串
因此 plot.ly
将 Resource
作为离散类别而不是连续度量。
task_list.Resource = task_list.Resource.apply(str)
import random
all_the_colors = list((x,y,z) for x in range(256) for y in range(256) for z in range(256))
colors = [f"rgb({random.choice(all_the_colors)})" for x in df.Resource.unique()]
def chart(task_list, filename):
fig = ff.create_gantt(task_list, colors=colors, index_col='Resource', show_colorbar=True, group_tasks=True)
# plot(fig, filename=filename)
return plot(fig, filename=filename, include_plotlyjs=False, output_type='div')
#print(fig)
如何更改图例栏和颜色以单独显示 Dataframe 中的每一行?我当前的图表如下所示:
代码如下:
def chart(task_list, filename):
fig = ff.create_gantt(task_list, colors='Rainbow', index_col='Resource', show_colorbar=True, group_tasks=True)
# plot(fig, filename=filename)
return plot(fig, filename=filename, include_plotlyjs=False, output_type='div')
#print(fig)
'Rainbow' 是默认的 plotly 色标。但是,如果我没记错的话,它仅限于两种颜色。
我只希望图表有一个类似于此的图例(无论是点还是线,只是不是像当前甘特图那样的渐变条):
代码如下:
df = [dict(Task="Job A", Start='2016-01-01', Finish='2016-01-02', Resource='Apple'),
dict(Task="Job B", Start='2016-01-02', Finish='2016-01-04', Resource='Grape'),
dict(Task="Job C", Start='2016-01-02', Finish='2016-01-03', Resource='Banana')]
colors = dict(Apple = 'rgb(220, 0, 0)',
Grape = 'rgb(170, 14, 200)',
Banana = (1, 0.9, 0.16))
fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True)
py.iplot(fig, filename='gantt-dictioanry-colors', world_readable=True)
但是,当我使用文档中的代码时,它只有有限数量的颜色,由字典 colors 设置。我希望颜色能够在 Dataframe 中有新行时自行生成。
TLDR;需要一个 COLORSCALE 能够容纳 Dataframe 中不断增加的行数,并将渐变条更改为 lines/dots/whatever 以根据 index_col.
作为每个 Dataframe 行的图例试试这个
在将 Resource
传递给 def chart(task_list, filename)
之前将其更改为字符串
因此 plot.ly
将 Resource
作为离散类别而不是连续度量。
task_list.Resource = task_list.Resource.apply(str)
import random
all_the_colors = list((x,y,z) for x in range(256) for y in range(256) for z in range(256))
colors = [f"rgb({random.choice(all_the_colors)})" for x in df.Resource.unique()]
def chart(task_list, filename):
fig = ff.create_gantt(task_list, colors=colors, index_col='Resource', show_colorbar=True, group_tasks=True)
# plot(fig, filename=filename)
return plot(fig, filename=filename, include_plotlyjs=False, output_type='div')
#print(fig)