我在极地图中添加了一个小徽标。
我正在使用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)
输出如下:
坐标(theta,r)
中AnnotationBbox
的标志中央启动。
我想将徽标移动到下面的红色框中所示的位置:
谁能告诉我该怎么做?
您可以使用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))
非常感谢@Diziet