Search code examples
pythonmatplotlibmatplotlib-basemapmap-projections

Matplotlib Mollweide/Hammer projection: region of interest only


I was wondering if there's a way to only show the region of interest from a plot based on Mollweide/Hammer projection in basemap (matplotlib).

I am trying to set the plot-bounds roughly to the Pacific plate, as in the link below. However, the set_xlim and set_ylim functions do not seem to have any effect. Thanks in advance for any guidance.

http://geology.gsapubs.org/content/29/8/695/F1.large.jpg


Solution

  • From the documentation, both Hammer and Mollweide projections don't allow this as they print out entire world maps. Here's some code using Polyconic projection, but it is bounded by straight lines. The trick here is to define the corner longitude and latitudes on creation.

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    import numpy as np
    
    my_map = Basemap(projection='poly', lat_0=0, lon_0=-160,
        resolution = 'h', area_thresh = 0.1,
        llcrnrlon=140, llcrnrlat=-60,
        urcrnrlon=-100, urcrnrlat=60)
    
    plt.figure(figsize=(16,12))
    
    my_map.drawcoastlines()
    my_map.drawcountries()
    my_map.fillcontinents(color='coral', lake_color='aqua')
    my_map.drawmapboundary(fill_color='aqua')
    
    my_map.drawmeridians(np.arange(0, 360, 20))
    my_map.drawparallels(np.arange(-90, 90, 10))
    
    plt.show()
    

    Result:

    enter image description here

    Note that this effectively shows less area than the one in the picture you provided.