自动换行 matplotlib x 轴标签

xyz*_*yne 5 python plot matplotlib

我正在尝试绘制带有长 x 标签字符串的图表。这篇文章描述了一个类似的问题(如何使用 自动换行 y 轴标签tight_layout),但对我来说不起作用,因为tight_layout改变了比例。另一篇文章描述了一种无法实现轴标签自动换行的方法 - 该包textwrap需要指定要换行的字符数。

我的代码:

import matplotlib.pyplot as plt
plt.figure()
plt.bar([0,1,2,3],[0,1,4,9])        
labels = ['superdupersuperduperlonglabel0','superdupersuperduperlonglabel1',
    'superdupersuperduperlonglabel2','superdupersuperduperlonglabel3']
plt.xticks([0,1,2,3],labels, wrap = True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

这是结果图,x 标签重叠: 这是结果图,x 标签重叠。

根据 matplotlib 文档:

文本属性可用于控制标签的外观。

wrap = True似乎没有正确包装 x 标签。有什么建议吗?