Search code examples
python-3.xmatplotlibmultiple-columnsaxis-labels

How can I split the `ylabel` of a matplotlib figure into rows?


How can I split the ylabel of a matplotlib figure into rows? I want to keep the ylabel on the y-axis rotated. As an example, here's my subplot so far, for which the relevant part of the code is below:

plt.ylabel('Spacing of Zeroes of $J_{\\nu}(x)$', rotation=0)

When I try doing this:

plt.ylabel('Spacing of Zeroes of $J_{\\nu}(x)$', rotation=0, ncol=2)

I receive this error:

AttributeError: Unknown property ncol

Solution

  • My suggestion would be to introduce linebreaks in the string.

    plt.ylabel('Spacing of\nZeroes of\n$J_{\\nu}(x)$', rotation=0, ha="right")
    

    enter image description here