4

我想在我的地图上放一个文字,比如卫星图像

import numpy as np, matplotlib.pyplot as plt    
from mpl_toolkits.basemap import Basemap    

m = Basemap(resolution='l',projection='geos',lon_0=-75.)    
fig = plt.figure(figsize=(10,8))    
m.drawcoastlines(linewidth=1.25)    
x,y = m(-150,80)
plt.text(x,y,'Jul-24-2012')

但是,文本“Jul-24-2012”并没有出现在我的图中。我想这是因为地图不在笛卡尔坐标中。

那么,谁能帮我弄清楚如何做到这一点,好吗?

4

1 回答 1

7

您的文本未显示的原因是您正在尝试绘制一个对您正在使用的地图投影无效的点。

如果您只想将文本放置在坐标轴坐标中的某个点(例如图的左上角),请使用annotate,而不是text.

事实上,您真正想要使用text. annotate更加灵活,并且实际上是针对注释绘图,而不仅仅是将文本放置在数据坐标中的 x,y 位置。(例如,即使您想在数据坐标中注释 x,y 位置,您通常希望文本从它偏移一个距离(以为单位,而不是数据单位。)

import matplotlib.pyplot as plt

from mpl_toolkits.basemap import Basemap

m = Basemap(resolution='l',projection='geos',lon_0=-75.)

fig = plt.figure(figsize=(10,8))

m.drawcoastlines(linewidth=1.25)

#-- Place the text in the upper left hand corner of the axes
# The basemap instance doesn't have an annotate method, so we'll use the pyplot
# interface instead.  (This is one of the many reasons to use cartopy instead.)
plt.annotate('Jul-24-2012', xy=(0, 1), xycoords='axes fraction')

plt.show()

在此处输入图像描述

于 2013-12-04T00:09:10.960 回答