Я пытаюсь нарисовать текст в границах некоторых линий. Строки можно поворачивать, и поэтому текст также необходимо вращать.
Когда я добавляю текст без поворота, кажется, что он имеет правильное расположение и размер. Однако после поворота это не так (лучше всего объяснить, если взглянуть на изображение).
Вот что я попробовал:
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1)
fig.set_dpi( 100 )
fig.set_size_inches( 1, 1 )
# Plot diagonal line (45 degrees)
ax.plot((0, 0),(0, 10))
ax.plot((10, 10), (0, 10))
ax.plot((0, 10), (10, 10))
ax.plot((0, 10), (0, 0))
ax.plot((0,10),(1.3,1.3)) # font size 10 has 13 pixels, hence 1.3
ax.plot((3,10),(3,10))
# compute the offset of the line that is exactly 1.3 above the diagonal
d = np.array([-1,1])
d = d / np.sqrt(sum(d**2)) * 1.3
u = np.array([3,3]) + d
ax.plot( (u[0], 10+u[0]-u[1]), (u[1], 10 ))
# set limits so that it no longer looks on screen to be 45 degrees
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
# Plot text
ax.text(0,0, 'In', fontsize=10 )
ax.text(4,0, 'Bbox', fontsize=10, bbox={"pad":0} )
ax.text(3,3, 'Out', fontsize=10, rotation=45, verticalalignment="bottom", \
horizontalalignment="left", rotation_mode="anchor" )
ax.text(6,6, 'Bbox', fontsize=10, rotation=45, verticalalignment="bottom", \
horizontalalignment="left", rotation_mode="anchor",bbox={"pad":0} )
plt.axis("off")
plt.savefig( "test.pdf", bbox_inches="tight" )
Это дает мне следующий вывод. График с повернутым, но смещенным текстом:

Обратите внимание, что "Out" не совсем вписывается в две соседние строки, как предполагалось.
Кто-нибудь идея о том, как настроить / исправить это?