I have a suptitle object that will sometimes be wrapped, using the built in wrapping functionality of Matplotlib. However, when trying to get the height of the suptitle, I seem to always get the height corresponding to one line. Where am I going wrong? This is what I'm trying with:
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
fig = Figure((4, 4))
FigureCanvas(fig)
text_1 = "I'm a short text"
text_2 = "I'm a longer text that will be wrapped autoamtically by Matplotlib, using wrap=True"
title = fig.suptitle(text_1, wrap=True)
fig.canvas.draw() # Draw text to find out how big it is
bbox = title.get_window_extent()
print(bbox.width) # 105
print(bbox.height) # 14
title = fig.suptitle(text_2, wrap=True)
fig.canvas.draw() # Draw text to find out how big it is
bbox = title.get_window_extent()
print(bbox.width) # 585 <-- This looks about right
print(bbox.height) # Still 14 even though this time the text is wrapped!
The same thing happens with Text
objects (using something like fig.text(0.5, 0.5, text_1, wrap=True)
.