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:
If you are looking for a fast way to wrap your labels dynamically, you can simply replace ' '
by '\n'
like this :
wrapped_labels = [ label.replace(' ', '\n') for label in labels ]