2016-06-19 7 views
0

Python Plotlyライブラリはplot graphs or networksに対応しています。Python Plotly library for networks:異なる色のノードを色付けする方法

(このlinkから)次のコードは、描画するノードの属性の異なる辞書を返す関数である:

def scatter_nodes(pos, labels=None, color=None, size=20, opacity=1): # pos is the dict of node positions # labels is a list of labels of len(pos), to be displayed when hovering the mouse over the nodes # color is the color for nodes. When it is set as None the Plotly default color is used # size is the size of the dots representing the nodes #opacity is a value between [0,1] defining the node color opacity L=len(pos) trace = Scatter(x=[], y=[], mode='markers', marker=Marker(size=[])) for k in range(L): trace['x'].append(pos[k][0]) trace['y'].append(pos[k][1]) attrib=dict(name='', text=labels , hoverinfo='text', opacity=opacity) # a dict of Plotly node attributes trace=dict(trace, **attrib)# concatenate the dict trace and attrib trace['marker']['size']=size trace['marker']['color']=color return trace

trace['marker']['color']=colorがすべてのノードに同じ色を割り当てます。

この行をtrace['marker']['color']=random.randint(500)に置き換えると、各ノードにランダムな色が付けられます。

私は、各ノードがキーとしてノードを持つ辞書と値としての色で事前に決められた色を持つことを望みます。

どうすればよいですか?

答えて

0

単純な答え:ノードで自動的にインデックス付けされる色のリストとしてcolorを定義する必要があります。

関連する問題