Networkx draw_networkx_edges capstyle

Does anyone know if it is possible to have fine-grained control over the properties of the line when drawing the edges of the network through (for example) draw_networkx_edges ? I would like to manage the 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() 

In the above example, there are gaps between the edges that I would like to hide while controlling the capstyle. I was thinking about adding nodes only in the right size to fill in the blanks, but the edges in my final graph are colored, so adding nodes will not reduce it. I cannot understand from the documentation or look at edges.properties() how to do what I want to do ... any suggestions?

Carson

+6
source share
1 answer

It looks like you cannot install capstyle in matplotlib linear collections.

But you can create your own collection of edges using Line2D objects that allow you to control the style:

 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() 
+7
source

All Articles