在极坐标图上更改图像的原点

Changing the origin of an image lay over the polar plot

我在极坐标图中添加了一个小标志。

我正在使用 python 来做到这一点。

我使用以下代码来执行此操作。

Logo = mpimg.imread(figpath+figname)
imagebox = OffsetImage(Logo, zoom=0.12)
ab = AnnotationBbox(imagebox, (4.7, 8))
ax1.add_artist(ab)
ax1.set_ylim(0,8)

输出结果如下:

AnnotationBbox 中的坐标 (theta,r) 从徽标的中心开始。

我要将logo移动到下图红框位置:

谁能告诉我该怎么做?

您可以使用 box_alignment=AnnotationBbox 来更改框的参考点。例如传递 box_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))