是的,这是绝对有可能的,但是如果你正在制作基于网络的地图,那么可能值得你看看D3.js(具体来说,地图见这个优秀教程http://bost.ocks.org/mike/map/)。
对于cartopy而言,我将一步步地介绍它,因为它是matplotlib和cartopy中转换系统的一个很好的演练。
首先,我们可以得到一个数字任意点的像素坐标:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()
# Define a transformation which takes latitude and longitude values,
# and returns pixel coordinates.
ll_to_pixel = ccrs.Geodetic()._as_mpl_transform(ax)
# We need to call draw to ensure that the axes location has been defined
# fully.
plt.draw()
# Now lets figure out the pixel coordinate of Sydney.
x_pix, y_pix = ll_to_pixel.transform_point([151.2111, -33.8600])
# We can even plot these pixel coordinates directly with matplotlib.
plt.plot(x_pix, y_pix, 'ob', markersize=25, transform=None)
plt.savefig('figure_1.png', dpi=plt.gcf().get_dpi())
plt.show()
现在我们要编写代码来生成区域地图,我会在必要的信息已经提前写下了全部评论(< 80行)。我已经发布了这个作为要点(https://gist.github.com/pelson/6308997),以便你可以检查出来,如果你喜欢,可以试试看。现场演示结果:https://rawgithub.com/pelson/6308997/raw/map.html