1 回答

TA贡献1826条经验 获得超6个赞
您可以使用 to 来更改框的参考点。例如,传递使右上角成为参考坐标。box_alignment=AnnotationBboxbox_alignment=(1,1)xy
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks
ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line
ax.grid(True)
img = matplotlib.image.imread("https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png")
imagebox = OffsetImage(img, zoom=0.12)
ab = AnnotationBbox(imagebox, xy=(np.pi*225/180, 2), box_alignment=(1,1))
ax.add_artist(ab)
plt.show()
请注意,您还可以更改用于放置框的坐标系。例如,如果您想将徽标放在图的左上角,则可以执行以下操作:
ab = AnnotationBbox(imagebox, xy=(0,1), xycoords='figure fraction', box_alignment=(0,1))
添加回答
举报