Search code examples
pythonmatplotlibplotlabel

How to show Y axis label horizontally


I'm creating very simple charts with matplotlib / pylab Python module. The letter "y" that labels the Y axis is on its side. You would expect this if the label was longer, such as a word, so as not to extend the outside of the graph to the left too much. But for a one-letter label, this doesn't make sense; the label should be upright.

How can I show the "y" horizontally?


Solution

  • It is very simple. After plotting the label, you can simply change the rotation:

    import matplotlib.pyplot as plt
    
    plt.ion()
    plt.plot([1, 2, 3])
    
    plt.ylabel("y", rotation=0)
    # or
    # h = plt.ylabel("y")
    # h.set_rotation(0)
    
    plt.draw()