I have the following code to draw a graph with nodes but i am failing to add a proper legend: (sorry, i can't post an image it seems i don't have enough reputation)
I want a legend with the 4 colors, such as "light blue = obsolese, red = Draft, Yellow = realease, dark blue = init".
I have seen some solutions with "scatter" but i think it is too complicated. Is there a way to do it with plt.legend(G.nodes)
?
Here is the code:
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
G=nx.Graph()
G.add_node("kind1")
G.add_node("kind2")
G.add_node("Obsolete")
G.add_node("Draft")
G.add_node("Release")
G.add_node("Initialisation")
val_map = {'kind1': 2,'kind2': 2,'Obsolete': 2,'Initialisation': 1,'Draft': 4,'Release': 3}
values = [val_map.get(node, 0) for node in G.nodes()]
nodes = nx.draw(G, cmap = plt.get_cmap('jet'), node_color = values)
plt.legend(G.nodes())
plt.show()