【问题标题】:matplotlib Basemap Fundamental Lunematplotlib Basemap Fundamental Lune
【发布时间】:2017-04-04 23:52:07
【问题描述】:

我正在尝试使用 matplotlib Fundamental Lune Plot 重新创建此投影。与此特定投影相关的参考资料在这里,Carl Tape Moment Tensors

绘图背后的地球物理学并不重要,但本质上它是经度 -30 到 30 度和纬度 -90 到 90 之间的投影。我认为底图可能是创建投影的好方法,但是我似乎无法弄清楚如何只显示这个基本的月形部分。这是我一直在玩的东西,但它仍然显示了整个地球:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

m = Basemap(
        resolution='l',     # coastline resolution, can be 'l' (low), 'h'
        projection='hammer', # Hammer projection
        lat_ts=0,          # latitude of true scale
        lon_0=0,          # longitude of the plotting domain center
        lat_0=0)           # latitude of the plotting domain center

# draw parallels and meridians.
m.drawparallels(np.arange(-90.,90.,10.))
m.drawmeridians(np.arange(-30.,31.,10.))
ax = plt.gca()
plt.show()

谁能提供一些指导或建议?

【问题讨论】:

    标签: python matplotlib matplotlib-basemap


    【解决方案1】:

    在 Basemap 中,我相信 Hammer 投影是“全球性的”,这意味着它不需要范围输入,因此整个地球总是会显示是有意义的。

    我不确定如何使用 Basemap 制作您正在寻找的那种绘图,但我认为,我可以使用 Cartopy 代替。以下代码在左下方生成图像,并带有一些演示数据:

    import matplotlib.pyplot as plt
    import numpy as np
    import cartopy.crs as ccrs
    import matplotlib.path as mpath
    
    # Mollweide projection
    fig = plt.figure()
    ax = fig.add_subplot(111, projection=ccrs.Mollweide())
    
    # Here I define a matplotlib Path object to use as the boundary
    outlinex = np.concatenate([[-30],np.tile(-30,180), np.tile(30,180),[-30]])
    outliney = np.concatenate([[-90],np.arange(-90,90),np.arange(89,-91,-1),[-90]])
    outlinecodes = np.array([mpath.Path.MOVETO]+[mpath.Path.LINETO]*360+[mpath.Path.MOVETO])
    outlinepath = mpath.Path(np.column_stack([outlinex[::-1], outliney[::-1]]), outlinecodes[::-1])
    
    # For good measure, plot some data
    ax.plot(np.arange(-10,25), np.linspace(80,45,35), transform=ccrs.Geodetic())
    ax.plot(np.tile(25,91),np.arange(45,-46,-1), transform=ccrs.Geodetic())
    
    # Plot gridlines and set the boundary
    ax.gridlines(xlocs=np.arange(-30,31,10), ylocs=np.arange(-90,91,45))
    ax.set_boundary(outlinepath, transform=ccrs.Geodetic(), use_as_clip_path=False)
    
    # The plotting will have automatically set the extents, so set them to what we want
    ax.set_extent((-30,30,-90,90))
    
    plt.show()
    

    请注意,如果您省略 set_boundary 元素而只使用 set_extent,您将获得右侧的图像,而不是左侧的图像。

    【讨论】:

    • 感谢您的建议。看起来它可能会起作用
    猜你喜欢
    • 2012-11-29
    • 2014-07-10
    • 2015-08-11
    • 2012-11-16
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多