networkx draw_networkx_edges capstyle [英] networkx draw_networkx_edges capstyle
问题描述
有人知道通过(例如)draw_networkx_edges
绘制networkx边时是否可以对线属性进行细粒度控制吗?我想控制solid_capstyle
和solid_joinstyle
行,它们是(matplotlib)Line2D
属性.
Does anyone know if it is possible to have fine-grained control over line properties when drawing networkx edges via (for example) draw_networkx_edges
? I would like to control the line solid_capstyle
and solid_joinstyle
, which are (matplotlib) Line2D
properties.
>>> import networkx as nx
>>> import matplotlib.pyplot as plt
>>> G = nx.dodecahedral_graph()
>>> edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G), width=7)
>>> plt.show()
在上面的示例中,我想通过控制样式来隐藏边缘之间的间隙".我考虑过以适当的大小添加节点以填充间隙,但是我最终图中的边缘是彩色的,因此添加节点不会对其进行裁剪.
我无法从文档中弄清楚,也无法查看edges.properties()
如何做我想做的事...有什么建议吗?
In the example above, there are 'gaps' between the edges which I'd like to hide by controlling the capstyle. I thought about adding the nodes at just the right size to fill in the gaps, but the edges in my final plot are coloured, so adding nodes won't cut it.
I can't figure out from the documentation or looking at edges.properties()
how to do what I want to do... any suggestions?
卡森
推荐答案
您似乎无法在matplotlib行集合上设置capstyle.
It looks like you can't set the capstyle on matplotlib line collections.
但是您可以使用Line2D对象创建自己的边缘集合,该对象可以控制capstyle:
But you can make your own collection of edges using Line2D objects which allows you to control the capstyle:
import networkx as nx
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
G = nx.dodecahedral_graph()
pos = nx.spring_layout(G)
ax = plt.gca()
for u,v in G.edges():
x = [pos[u][0],pos[v][0]]
y = [pos[u][1],pos[v][1]]
l = Line2D(x,y,linewidth=8,solid_capstyle='round')
ax.add_line(l)
ax.autoscale()
plt.show()
这篇关于networkx draw_networkx_edges capstyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!