跃然一笑
您可以使用 to 来更改框的参考点。例如,传递使右上角成为参考坐标。box_alignment=AnnotationBboxbox_alignment=(1,1)xyfrom matplotlib.offsetbox import OffsetImage, AnnotationBboxr = np.arange(0, 2, 0.01)theta = 2 * np.pi * rfig = 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 ticksax.set_rlabel_position(-22.5) # Move radial labels away from plotted lineax.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))