networkx - 为什么会有“预期任一字符串的元素”
问题描述
import networkx as nx
from bokeh.transform import linear_cmap
from bokeh.io import show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Circle, HoverTool, TapTool, BoxSelectTool
from bokeh.models.graphs import from_networkx
from bokeh.palettes import Spectral6
output_notebook()
G=nx.Graph(G_fb)
plot = figure(x_range=(-1.1, 1.1), y_range=(-1.1, 1.1))
plot.add_tools(HoverTool(tooltips=[("Name", "@name"),
("Club", "@club")]),
TapTool(),
BoxSelectTool())
graph = from_networkx(G, nx.spring_layout, iterations=1000, scale=1, center=(0,0))
graph.node_renderer.data_source.data['name'] = list(G.nodes())
graph.node_renderer.glyph = Circle(size=10)
graph.node_renderer.glyph = Circle(
size=10,
fill_color=linear_cmap(degrees, palette=Spectral6,low=0, high=100, low_color='blue', high_color='red')
plot.renderers.append(graph)
show(plot)
它出现了一个错误说:
期望 String、Dict(Enum('expr', 'field', 'value', 'transform'), Either(String, Instance(Transform), Instance(Expression), Color)) 或 Color 的元素,得到 { '字段': [5, 6, 12, 7, 8, 6, 6, 9, 8, 4, 3, 5, 5, 7, 5, 7, 4, 4, 3, 6, 3, 5, 10 , 1, 7, 4, 8, 2, 9, 6, 5, 5, 9, 11, 11, 3, 9, 1, 10, 1, 6, 6, 5, 8, 7, 7, 4, 7 , 2, 1, 3, 1, 6, 3, 1, 1, 2, 2, 1, 2, 2, 1], '变换': LinearColorMapper(id='1194', ...)}
G_fb 的一部分: 11 1 15 1 16 1 41 1 43 1 48 1 18 2 20 2 27 2 28 2 29 2 37 2 42 2 55 2 11 3 43 3 45 3 62 3 9 4 15 4 60 4 52 5 10 6 14 6 57 6 58 6 10 7 14 7 18 7 55 7 57 7 58 7 20 8 28 8 31 8 41 8 55 8 21 9 29 9 38 9 46 9 60 9 14 10 18 10 33 10 42 10 58 10 3 43 11 48 11 52 12 34 13 18 14 33 14 42 14 55 14 58 14 17 15 25 15 34 15 35 15 38 15 39 15 41 15 44 15 51 15 53 15 19 16
解决方案
推荐阅读
- javascript - 如何将数据传递给 Javascript 中的类对象?
- javascript - angular fire/firebase > fetch 集合并为每个文档获取其子集合
- html - 有没有办法针对单个元素?
- c# - C# Xunit 代码:文件结束预期错误。无法为我的生活弄清楚这是什么原因
- reactjs - 使用 JEST 在 ReactJS 单元测试中期望返回 HTML
- c - 查找文件是目录还是文件
- javascript - 如何使用 express.js app.delete 从数组中删除特定对象?
- c++ - 如何使用 sigwait() 使用信号的延迟
- c++ - 绑定可变参数函数 C++
- javascript - Image() 不接受宽度和高度