Home > Net >  How to put text in the top right corner of networkx drawing
How to put text in the top right corner of networkx drawing

Time:10-11

I am drawing a graph and would like to add some text in the top right corner. However I am not sure how to do this. I tried:

import matplotlib.pyplot as plt
import networkx as nx
import pydot
from networkx.drawing.nx_pydot import graphviz_layout

T = nx.balanced_tree(2, 5)


pos = graphviz_layout(T, prog="dot")
nx.draw(T, pos, node_color="y", edge_color='#909090', node_size=200, with_labels=True)

plt.text(0,0,"******************")
plt.show()

to see if I could show any text at all. It does show the asterisks in the bottom left. How do I know the resolution of the diagram so I can work out where the top right is?

CodePudding user response:

You can read in enter image description here

  • When using x=, the title is centered over x on the x-axis; adjust the value for precise positioning.
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(10, 4))
ax1.set_title('Title for NetworkX', loc='right')

ax2.set_title('Title for NetworkX', x=.68)

ax3.set_title('Title for NetworkX', x=1)
fig.tight_layout()

enter image description here

  • Related