Wrapping long y labels in matplotlib tight layout using setp

I have tried using textwrap on the labels and it works for me.

from textwrap import wrap
labels=['Really really really really really really long label 1',
        'Really really really really really really long label 2',
        'Really really really really really really long label 3']
labels = [ '\n'.join(wrap(l, 20)) for l in labels ]

Inserting this in your code gives us:

Wrapped labels

Leave a Comment