0

Expanding on this question, Is it possible to only display values of edge attributes?

For instance, currently using

paragraph = """
John is a computer scientist. John eats mango. John has an elder sister named Mary.
"""

mg.make_graph(paragraph) #This is my custom method, which creates the following graph

nx.draw(mg,pos=graphviz_layout(mg,prog='neato'),arrows=True,with_labels=True,alpha=0.5,linewidths=0.5,scale=2)
nx.draw_networkx_edge_labels(mg, pos = graphviz_layout(mg, prog='neato'),labels = nx.get_edge_attributes(mg,'label'))
plt.show()

I am getting this Output

However I only want the value of the attribute and not the key itself. (The word 'label' must not be printed.

I understand this is because nx.get_edge_attributes(mg,'label') returns a dictionary, but using nx.get_edge_attributes(mg,'label').values() in the labels parameter, also does not result in the graph being displayed with only values.

How can I achieve this? (i.e, only the value must be printed in edge and not the key label).

Community
  • 1
  • 1
Riken Shah
  • 3,022
  • 5
  • 29
  • 56

1 Answers1

-1

How about something along the lines of:

labels = {e: mg.get_edge_data(e[0], e[1])["label"] for e in mg.edges()}
nx.draw_networkx_edge_labels(mg, pos=graphviz_layout(mg, prog='neato'), edge_labels=labels)

labels needs to be a dictionary with edges as keys and labels you want to be drawn as values. Note that I put the argument containing labels as edge_labels since it is the name in version 1.10 and 2. But I think you can adapt if you have an older version.

Zaccharie Ramzi
  • 2,106
  • 1
  • 18
  • 37