Search code examples
matplotlibprojectionmatplotlib-basemap

basemap round stereographic plot mapboundary cropped


I'm struggling with round stereographic plots using the matplotlib basemap toolkit. I always get a cropped map boundary at the top, bottom and left, right. The example code:

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

m = Basemap(projection='spstere', boundinglat=-60, lon_0=180,
lat_ts=-71, round=True, ellps='WGS84')

m.drawparallels(np.arange(-90.,-60.0, 10.), linewidth=0.1)
m.drawmeridians(np.arange(-180.,181.,45.), linewidth=0.1, latmax=90)
m.drawmapboundary(linewidth=2, color='k')

plt.savefig("test.png",dpi=600, transparent=True)
plt.show()

This results in: cropped map boundary

I marked the cropped off part with red ellipses (top and left). It doesn't make a difference if I change the "linewidth" parameter.

Is there a workaround for this problem to make the boundary evenly in line width? Thanks for any help and suggestions in advance!


Solution

  • The circle that defines the map boundary is clipped by the actual axes in use. You may use the clip_on option to let it not be clipped.

    circle = m.drawmapboundary(linewidth=2, color='k')
    circle.set_clip_on(False)
    

    The example code then look like this

    from mpl_toolkits.basemap import Basemap
    import numpy as np
    import matplotlib.pyplot as plt
    
    m = Basemap(projection='spstere', boundinglat=-60, lon_0=180,
    lat_ts=-71, round=True, ellps='WGS84')
    
    m.drawparallels(np.arange(-90.,-60.0, 10.), linewidth=0.1)
    m.drawmeridians(np.arange(-180.,181.,45.), linewidth=0.1, latmax=90)
    circle = m.drawmapboundary(linewidth=2, color='k')
    circle.set_clip_on(False)
    
    plt.savefig("test.png",dpi=600, transparent=True)
    plt.show()
    

    enter image description here