Я следую руководству по программе для визуализации подключений к Facebook, и я получаю сообщение «TypeError: могу только объединить кортеж (не« список ») в кортеж», и я не знаю, как решить эту проблему
colors = cl.scales['12']['qual']['Paired']
def scatter_nodes(pos, labels=None, color='rgb(152, 0, 0)', size=8, opacity=1):
trace = Scatter(x=[],
y=[],
mode='markers',
marker=Marker(
showscale=False,
colorscale='Greens',
reversescale=True,
color=[],
size=10,
line=dict(width=0)))
for nd in nodeID:
trace['x'].append(pos[nd][0])
trace['y'].append(pos[nd][1])
color = colors[part[nd] % len(colors)]
trace['marker']['color'].append(color)
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
return trace
def scatter_edges(G, pos, line_color='#a3a3c2', line_width=1, opacity=.2):
trace = Scatter(x=[],
y=[],
mode='lines'
)
for edge in G.edges():
trace['x'] += [pos[edge[0]][0],pos[edge[1]][0], None]
trace['y'] += [pos[edge[0]][1],pos[edge[1]][1], None]
trace['hoverinfo']='none'
trace['line']['width']=line_width
if line_color is not None: # when it is None a default Plotly color is used
trace['line']['color']=line_color
return trace
labels = []
for nd in nodeID:
labels.append('{} ({})'.format(nd, part[nd],))
trace1 = scatter_edges(G, pos, line_width=0.25)
trace2 = scatter_nodes(pos, labels=labels)
Я пытался заменить его на круглые скобки, но это тоже не сработало.
Сообщение об ошибке
TypeError Traceback (most recent call last)
<ipython-input-26-7db6d16fa847> in <module>
----> 1 trace1 = scatter_edges(G, pos, line_width=0.25)
2 trace2 = scatter_nodes(pos, labels=labels)
<ipython-input-23-0e8ff4c52f3c> in scatter_edges(G, pos, line_color, line_width, opacity)
5 )
6 for edge in G.edges():
----> 7 trace['x'] += [pos[edge[0]][0],pos[edge[1]][0], None]
8 trace['y'] += [pos[edge[0]][1],pos[edge[1]][1], None]
9 trace['hoverinfo']='none'
TypeError: can only concatenate tuple (not "list") to tuple