A = [
[0, 1, 0, .8, 0],
[0, 0, .4, 0, .3],
[0, 0, 0, 0, 0],
[0, 0, .6, 0, .7],
[0, 0, 0, .2, 0]]
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
G = nx.from_numpy_matrix(np.matrix(A))
edge_labels=nx.draw_networkx_edge_labels(G,pos=nx.spring_layout(G))
nx.draw(G)
plt.show()
draw_networkx_edge_labels
draw_networkx_edge_labels(G, pos, edge_labels=None, label_pos=0.5, font_size=10, font_color='k', font_family='sans-serif', font_weight='normal', alpha=1.0, bbox=None, ax=None, rotate=True, **kwds)[source]
Draw edge labels.
Parameters:
G (graph) – A networkx graph
pos (dictionary) – A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.
ax (Matplotlib Axes object, optional) – Draw the graph in the specified Matplotlib axes.
alpha (float) – The text transparency (default=1.0)
edge_labels (dictionary) – Edge labels in a dictionary keyed by edge two-tupleof text labels (default=None). Only labels for the keys in the dictionary are drawn.
label_pos (float) – Position of edge label along edge (0=head, 0.5=center, 1=tail)
font_size (int) – Font size for text labels (default=12)
font_color (string) – Font color string (default=’k’ black)
font_weight (string) – Font weight (default=’normal’)
font_family (string) – Font family (default=’sans-serif’)
bbox (Matplotlib bbox) – Specify text box shape and colors.
clip_on (bool) – Turn on clipping at axis boundaries (default=True)
Returns:
dict of labels keyed on the edges
Return type:
dict