58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import matplotlib.pyplot as plt
|
|
import networkx as nx
|
|
from netgraph import Graph
|
|
|
|
G = nx.Graph( )
|
|
#G = Graph( G0, edge_layout='curved')
|
|
|
|
VERY_HIGH, HIGH, MEDIUM, USUAL = 0.2, 0.4, 0.7, 0.9
|
|
|
|
|
|
G.add_edge("raze", "obliterate", weight=MEDIUM)
|
|
G.add_edge("eradicate", "obliterate", weight=VERY_HIGH)
|
|
G.add_edge("erase", "obliterate", weight=VERY_HIGH)
|
|
G.add_edge("abolish", "obliterate", weight=VERY_HIGH)
|
|
G.add_edge("destroy", "obliterate", weight=VERY_HIGH)
|
|
|
|
|
|
G.add_edge("raze", "demolish", weight=VERY_HIGH)
|
|
G.add_edge("raze", "destroy", weight=VERY_HIGH)
|
|
G.add_edge("raze", "ruin", weight=VERY_HIGH)
|
|
G.add_edge("raze", "devastate", weight=VERY_HIGH)
|
|
G.add_edge("raze", "shatter", weight=VERY_HIGH)
|
|
G.add_edge("raze", "wreck", weight=VERY_HIGH)
|
|
G.add_edge("raze", "smash", weight=VERY_HIGH)
|
|
|
|
|
|
elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] > 0.5]
|
|
esmall = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] <= 0.5]
|
|
|
|
|
|
G1 = Graph( G, edge_layout='curved')
|
|
nx.draw_networkx_labels(G1, font_size=20, font_family="sans-serif")
|
|
plt.show()
|
|
#pos = nx.spring_layout(G, seed=7) # positions for all nodes - seed for reproducibility
|
|
pos = nx.spring_layout(G)
|
|
# nodes
|
|
nx.draw_networkx_nodes(G, pos) # , node_size=700)
|
|
|
|
# edges
|
|
nx.draw_networkx_edges(G, pos )
|
|
# nx.draw_networkx_edges(G, pos ,# edgelist=elarge, width=6,
|
|
# connectionstyle="arc3,rad=0.1")
|
|
# nx.draw_networkx_edges(
|
|
# G, pos, #edgelist=esmall, width=6, #, alpha=0.5, edge_color="b", #, style="dashed",
|
|
# connectionstyle="arc3,rad=0.1"
|
|
# )
|
|
|
|
# node labels
|
|
nx.draw_networkx_labels(G, pos, font_size=20, font_family="sans-serif")
|
|
# edge weight labels
|
|
edge_labels = nx.get_edge_attributes(G, "weight")
|
|
nx.draw_networkx_edge_labels(G, pos, edge_labels)
|
|
|
|
ax = plt.gca()
|
|
ax.margins(0.08)
|
|
plt.axis("off")
|
|
plt.tight_layout()
|
|
plt.show() |