Issue
I have a graph in networkx with many edges that will overlap. I'm attempting to make them transparent so that the accumulation of edges will build up a darker colour, but however many edges are overlapping they are still the same shade of pale. For example with one edge:
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
G = nx.Graph()
colorlist = []
G.add_edge(1,2)
# explicitly set positions
nodes = {1: (1,0),
2: (0,1)}
nx.draw_networkx(G, nodes, alpha=0.1)
ax = plt.gca()
plt.axis("off")
plt.show()
but when six transparent lines are layered over each other
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
G = nx.Graph()
colorlist = []
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
# explicitly set positions
nodes = {1: (1,0),
2: (0,1)}
nx.draw_networkx(G, nodes, alpha=0.1)
ax = plt.gca()
plt.axis("off")
plt.show()
why does layering transparent lines over each other not make a darker line, and how can I make this happen?
Solution
You need to use MultiGraph
instead of Graph
. Otherwise, your graph will still contain only one edge, even if you add it multiple times.
The following will create the desired image with "darker" edges:
G = nx.MultiGraph()
colorlist = []
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
G.add_edge(1,2)
# explicitly set positions
nodes = {1: (1,0),
2: (0,1)}
nx.draw_networkx(G, nodes, alpha=0.1)
ax = plt.gca()
plt.axis("off")
plt.show()
Answered By - Sparky05
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.