Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using networkx draw_networkx_labels with the keyword rotation='vertical' does not rotate label text

I am using Networkx to draw a Hierarchy Graph. I would like to rotate the labels to a vertical position, using the rotation keyword seems to have no effect.

    nx.draw_networkx_labels(G, pos=lbl_pos, rotation='vertical')

Is it possible to draw the labels with a vertical rotation?

like image 280
MicheleM Avatar asked Jan 24 '17 17:01

MicheleM


1 Answers

If you capture the output of nx.draw_networkx_labels() you can adjust all of the text parameters. For example,

In [1]: import networkx as nx

In [2]: G = nx.path_graph(4)

In [3]: pos = nx.spring_layout(G)

In [4]: nx.draw_networkx(G,pos,with_labels=False)

In [5]: text = nx.draw_networkx_labels(G,pos)

In [6]: for _,t in text.items():
    t.set_rotation('vertical')
   ...:     

enter image description here

like image 117
Aric Avatar answered Nov 10 '22 13:11

Aric