Python 带有html区域链接的卡通国家地图
我一直按照用户pelson的指示创建一个填充了国家形状的地图。() 现在,我很想把这一步进一步,创建一个html站点,如下所示: 我不需要那些别致的弹出窗口,但是每个国家的链接()都会很好。 是否可以使用cartopy创建这些坐标列表?Python 带有html区域链接的卡通国家地图,python,html,matplotlib,cartopy,Python,Html,Matplotlib,Cartopy,我一直按照用户pelson的指示创建一个填充了国家形状的地图。() 现在,我很想把这一步进一步,创建一个html站点,如下所示: 我不需要那些别致的弹出窗口,但是每个国家的链接()都会很好。 是否可以使用cartopy创建这些坐标列表? 我正在寻找一个生成静态html文件的全自动脚本。是的,这绝对是可能的,但如果您正在生成基于web的地图,那么您可能值得看看D3.js(具体来说,有关地图,请参阅本优秀教程) 但是对于cartopy,我将一步一步地介绍它,因为它是matplotlib和cartop
我正在寻找一个生成静态html文件的全自动脚本。是的,这绝对是可能的,但如果您正在生成基于web的地图,那么您可能值得看看D3.js(具体来说,有关地图,请参阅本优秀教程) 但是对于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()
现在我们有了编写代码生成区域地图所需的信息,我已经写了完整的注释(是的,这绝对是可能的,但是如果您正在生成基于web的地图,那么可能值得您阅读D3.js(具体来说,对于地图,请参阅本优秀教程) 但是对于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()
现在我们有了编写代码生成区域图所需的信息,我已经写了完整的注释(