【发布时间】:2019-07-02 11:27:07
【问题描述】:
我想将 MultiLine 与提供 LineWidth 的列表一起使用,以便图表中的每条边都以不同的宽度绘制。下面是从documentation 中提取的一个简化示例,它会引发错误。是否有可能使用不同宽度的 MultiLine?或者您知道绘制不同宽度图形的不同方法吗?
import networkx as nx
from bokeh.io import show, output_file
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxSelectTool
from bokeh.models.graphs import from_networkx
from bokeh.palettes import Spectral4
import numpy as np
G=nx.karate_club_graph()
ewidth = [np.random.random() for (u, v, d) in G.edges(data=True)]
plot = Plot(plot_width=400, plot_height=400,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.title.text = "Graph Interaction Demonstration"
plot.add_tools(HoverTool(tooltips=None), TapTool(), BoxSelectTool())
graph_renderer = from_networkx(G, nx.circular_layout, scale=1, center=(0,0))
graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
#this works:
#graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=5)
# this doesnt work:
graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=ewidth)
plot.renderers.append(graph_renderer)
output_file("interactive_graphs.html")
show(plot)
【问题讨论】: