[英]How can I annotate text in Basemap using the exact coordinates of the location in Python?
我使用以下代码行创建了亚洲底图。 使用的投影是“marcator”。 我想在此底图中显示的区域是尼泊尔奇旺。 还提供了坐标。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
chitwan = (27.618556599999998, 84.45385600798173)
fig = plt.figure()
ax = fig.add_axes([0.5, 0.5, 2, 2]) #left, bottom, width, height
m = Basemap(
llcrnrlon = 30,
llcrnrlat = 0,
urcrnrlon = 120,
urcrnrlat = 60,
projection = "merc",
resolution = "l"
)
m.plot(chitwan[1], chitwan[0],
latlon = True,
marker = "s",
color = "blue",
markersize = 20)
m.drawcoastlines()
m.fillcontinents()
m.drawcountries()
m.drawstates()
plt.annotate(text = "Chitwan, Nepal", xy = chitwan)
plt.show()
我可以使用在尼泊尔奇旺添加一个蓝色方形标记
m.plot(chitwan[1], chitwan[0],
latlon = True,
marker = "s",
color = "blue",
markersize = 40)
传递latlon = True
允许我直接使用该地点的坐标绘制标记。
但是,我还想在同一位置将“Chitwan, Nepal”注释为文本。 我试过plt.annotate(text = "Chitwan, Nepal", xy = chitwan)
。 但是,这会将文本绘制在 Basemap 的左下角,如下所示。
我认为这应该是因为文本的经纬度坐标没有投影到 Basemap 的坐标上。 那么如何投影我的位置坐标,以便文本也插入与标记相同的位置? 是否可以通过直接传递该地点的确切坐标并为标记传递类似于latlon = True
的参数来做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.