Search code examples
python-2.7matplotlibdrawnetworkxlabel

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?


Solution

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

    import networkx as nx
    G = nx.path_graph(4)
    pos = nx.spring_layout(G)
    nx.draw_networkx(G, pos, with_labels=False)
    text = nx.draw_networkx_labels(G, pos)
    for _, t in text.items():
        t.set_rotation('vertical')