[SOLVED] How change scale data source

Hi every one, Iโ€™m working with networkx and Iโ€™m trying to display my network.

Here the result I get :

And here is the function that generate the html to display the graphe :

1      def HTMLgenerator(_network):
2              _pos = nx.get_node_attributes(_network.R_graph, 'pos')
3  
4              _dmin = 1
5              _ncenter = 0
6              for n in _pos:
7                  _x, _y = _pos[n]
8                  _d = (_x - 0.5) ** 2 + (_y - 0.5) ** 2
9                  if _d < _dmin:
10                     _ncenter = n
11                     _dmin = _d
12 
13             _p = nx.single_source_shortest_path_length(_network.R_graph, _ncenter)
14 
15             edge_trace = go.Scatter(
16                 x=[],
17                 y=[],
18                 line=dict(width=0.5, color='#888'),
19                 hoverinfo='none',
20                 mode='lines')
21 
22             for edge in _network.R_graph.edges():
23                 x0, y0 = _network.R_graph.node[edge[0]]['pos']
24                 x1, y1 = _network.R_graph.node[edge[1]]['pos']
25                 edge_trace['x'] += tuple([x0, x1, None])
26                 edge_trace['y'] += tuple([y0, y1, None])
27 
28             node_trace = go.Scatter(
29                 x=[],
30                 y=[],
31                 text=[],
32                 mode='markers',
33                 hoverinfo='text',
34                 marker=dict(
35                     showscale=True,
36                     # colorscale options
37                     # 'Greys' | 'YlGnBu' | 'Greens' | 'YlOrRd' | 'Bluered' | 'RdBu' |
38                     # 'Reds' | 'Blues' | 'Picnic' | 'Rainbow' | 'Portland' | 'Jet' |
39                     # 'Hot' | 'Blackbody' | 'Earth' | 'Electric' | 'Viridis' |
40                     colorscale='Reds',
41                     reversescale=True,
42                     color=[],
43                     size=10,
44                     colorbar=dict(
45                         thickness=15,
46                         title='Battery level',
47                         xanchor='left',
48                         titleside='right'
49                     ),
50                     line=dict(width=2)))
51 
52             for node in _network.R_graph.nodes():
53                 x, y = _network.R_graph.node[node]['pos']
54                 node_trace['x'] += tuple([x])
55                 node_trace['y'] += tuple([y])
56 
57             for node, adjacencies in enumerate(_network.R_graph.adjacency()):
58                 node_trace['marker']['color'] += tuple([len(adjacencies[1])])
59 
60     			node_info = "Sensor nยฐ" + str(node) + " | " + \
61     						"Energy : " + str(_network.R_graph.node[node]['energy']) + " | " + \
62     						str(len(adjacencies[1])) + " adjacencies"
63 
64                 node_trace['text'] += tuple([node_info])
65 
66             fig = go.Figure(data=[edge_trace, node_trace],
67                             layout=go.Layout(
68                                 title='',
69                                 titlefont=dict(size=16),
70                                 showlegend=False,
71                                 hovermode='closest',
72                                 margin=dict(b=20, l=5, r=5, t=40),
73                                 annotations=[dict(
74                                     text="",
75                                     showarrow=False,
76                                     xref="paper", yref="paper",
77                                     x=0.005, y=-0.002)],
78                                 xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
79                                 yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
80 
81             html = plotly.offline.plot(fig, auto_open=False, output_type='div')
82             return """<html><head><meta charset="utf-8" /></head><body><script type="text/javascript">window.PlotlyConfig = 
83                         {MathJaxConfig: 'local'};</script>""" \
84                    + html \
85                    + """<script type="text/javascript">window.addEventListener("resize", function(){Plotly.Plots.resize(docu
86                         ment.getElementById("611e9c72-ed73-4e6f-b171-1737e84f4735"));});</script></body></html>"""

โ€™

By default the scale is showing the number of connected nodes but I want it to show the battery level.
I tried searching in the โ€œscatterโ€ documentation but nothing helped me.

Can someone help me ?

I find it : line 40 there is color=[]
and the color is fill line 58 by

len(adjacencies[1]

I had to replace it by my value

_network.R_graph.node[node]['energy']