【问题标题】:cartopy country map with html area links带有 html 区域链接的 cartopy 国家地图
【发布时间】:2013-08-22 12:25:18
【问题描述】:

我一直按照用户 pelson 的说明创建一张带有填充国家形状的地图。 (Fill countries in python basemap)

现在我很想把这一步更进一步,并创建一个像这样的 html 网站: http://www.ethnologue.com/region/NEU 我不需要那些花哨的弹出窗口,但每个国家/地区的那些链接 (http://www.w3schools.com/tags/att_area_href.asp) 会非常好。 是否可以使用 cartopy 创建这些坐标列表? 我正在寻找一个生成静态 html 文件的全自动脚本。

【问题讨论】:

    标签: python html matplotlib cartopy


    【解决方案1】:

    是的,这绝对是可能的,但是如果您正在制作基于 Web 的地图,那么可能值得您查看 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()
    

    现在我们有了编写生成区域图的代码所需的信息,我已经继续使用完整的 cmets(https://gist.github.com/pelson/6308997) 发布,以便您可以查看并尝试一下,如果您愿意的话。对于结果的现场演示:https://rawgithub.com/pelson/6308997/raw/map.html

    【讨论】:

      猜你喜欢
      • 2020-10-08
      • 2021-03-03
      • 2014-05-21
      • 2014-10-15
      • 2011-07-21
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多