有一个类似的问题- 但我无法使那里提出的解决方案起作用。
这是一个带有长标题的示例图:
#!/usr/bin/env python
import matplotlib
import matplotlib.pyplot
import textwrap
x = [1,2,3]
y = [4,5,6]
# initialization:
fig = matplotlib.pyplot.figure(figsize=(8.0, 5.0))
# lines:
fig.add_subplot(111).plot(x, y)
# title:
myTitle = "Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all."
fig.add_subplot(111).set_title("\n".join(textwrap.wrap(myTitle, 80)))
# tight:
(matplotlib.pyplot).tight_layout()
# saving:
fig.savefig("fig.png")
它给出了一个
AttributeError: 'module' object has no attribute 'tight_layout'
如果我用它替换(matplotlib.pyplot).tight_layout()
它fig.tight_layout()
会给出:
AttributeError: 'Figure' object has no attribute 'tight_layout'
所以我的问题是 - 我如何使标题适合情节?