我有数据框,我使用graphviz
for id_key, group in df.groupby('ID'):
f = Digraph('finite_state_machine', filename='fsm.gv', encoding='utf-8')
f.body.extend(['rankdir=LR', 'size="5,5"'])
f.attr('node', shape='box')
for i in range(len(group)-1):
f.edge(str(group['category'].iloc[i]), str(group['category'].iloc[i+1]),
label=str(group['search_term'].iloc[i+1]))
f.render(filename=str(id_key))
答案 0 :(得分:2)
您可以使用其中一个brewer color schemes。例如:
g = graphviz.Digraph(format='png')
g.body.extend(["rankdir=LR"])
for i in range(9):
g.edge(str(i),str(i+1),color="/spectral9/"+str(i+1))
g.render(filename="example")
产生
如果您希望自己生成颜色,可以使用hsv format常量饱和度& 值并增加色调:
n = 20
g = graphviz.Digraph(format='png')
g.body.extend(["layout=circo"])
for i in range(n):
g.edge(str(i),str(i+1),color="{h:} 1 1".format(h=i/n))
g.edge(str(n),str(0),color="1 1 1")
g.render(filename="example")
产生