У меня есть объект suptitle, который иногда будет переноситься, используя встроенную функциональность переноса Matplotlib.Однако, пытаясь получить высоту субтитра, я всегда получаю высоту, соответствующую одной строке.Куда я иду не так?Вот что я пытаюсь сделать:
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!
То же самое происходит с Text
объектами (используя что-то вроде fig.text(0.5, 0.5, text_1, wrap=True)
.