python - Matplotlib: Focus on specific lon/lat using spstere projection -


i trying focus map on specific area of antarctica using 'spstere' projection matplotlib package in python. able plot whole of antarctica time want 'zoom' in , have closer @ specific area of continent.

similar examples using other projections (pyplot contour plot - clabel spacing; http://matplotlib.org/basemap/api/basemap_api.html; https://matplotlib.org/basemap/users/examples.html) available online have not been able apply 'spstere' projection on antarctica.

i want focus map on region of antarctic peninsula, spans

llcrnrlon=-100,urcrnrlon=-30,llcrnrlat=-90,urcrnrlat=-55.0

i have tried use code 'spstere' proj python takes account boundinglat , lon_0. i've tried change values boundinglat , lon_0 not work either.

any idea how go about? have tried using other projections such 'cyl' instead of getting nice square 'spstere' proj, horizontal rectangle.

m = basemap(projection='cyl',lon_0=0,lat_0=0,\       llcrnrlon=-180,urcrnrlon=180,llcrnrlat=-90,urcrnrlat=-55.0,resolution='c') 

any highly appreciated!

using polar stereographic projection 'spstere', can antarctic region using e.g. boundinglat=-60:

from mpl_toolkits.basemap import basemap import matplotlib.pyplot plt  m = basemap(projection='spstere',boundinglat=-60,lon_0=180,resolution='c') m.drawcoastlines()  plt.show() 

enter image description here

note 'spstere' centered @ south pole.
in order have map, not centered @ south pole, need use "stere" projection. setting corners "stere" projection not straigt forward.

one may therefore use plot in 'spstere' projection , find points enclose region of interest. in case e.g.

from mpl_toolkits.basemap import basemap import matplotlib.pyplot plt import numpy np  m = basemap(projection='spstere',boundinglat=-50,             lon_0=180+(-100+-30)/2.,resolution='c')  m.drawmeridians(np.arange(0,360,30),labels=[1,1,1,0]) m.drawparallels(np.arange(-90,90,5)) m.drawcoastlines()  xll, yll = m(-150,-70) # <-- find points looking @ meridians , parallels xur, yur = m(-30,-55) m.scatter([xll,xur], [yll, yur], c="crimson") plt.show() 

enter image description here

using points, (-150,-70, -30,-55), corners of map, can plot map using 'stere' projection.

m = basemap(projection='stere',resolution='c',             lat_0=-90, lon_0=(-100+-30)/2.,  lat_ts=(-90.+-55.)/2.,             llcrnrlon=-150,urcrnrlon=-30,llcrnrlat=-70,urcrnrlat=-55) 

enter image description here

if heuristic method not wanted, may automate procedure creating dummy map in 'spstere' projection, calculate coordinates rectangle in question (llcrnrlon=-100,urcrnrlon=-30,llcrnrlat=-90,urcrnrlat=-55.0) , create new basemap in stere projection them. function below taken activestate site (author pg).

from mpl_toolkits.basemap import basemap import matplotlib.pyplot plt import numpy np  def polar_stere(lon_w, lon_e, lat_s, lat_n, **kwargs):     '''returns basemap object (nps/sps) focused in region.     lon_w, lon_e, lat_s, lat_n -- graphic limits in geographical coordinates.                                   w , s directions negative.     **kwargs -- aditional arguments basemap object.     '''     lon_0 = lon_w + (lon_e - lon_w) / 2.     ref = lat_s if abs(lat_s) > abs(lat_n) else lat_n     lat_0 = np.copysign(90., ref)     proj = 'npstere' if lat_0 > 0 else 'spstere'     prj = basemap(projection=proj, lon_0=lon_0, lat_0=lat_0,                           boundinglat=0, resolution='c')     lons = [lon_w, lon_e, lon_w, lon_e, lon_0, lon_0]     lats = [lat_s, lat_s, lat_n, lat_n, lat_s, lat_n]     x, y = prj(lons, lats)     ll_lon, ll_lat = prj(min(x), min(y), inverse=true)     ur_lon, ur_lat = prj(max(x), max(y), inverse=true)     return basemap(projection='stere', lat_0=lat_0, lon_0=lon_0,                            llcrnrlon=ll_lon, llcrnrlat=ll_lat,                            urcrnrlon=ur_lon, urcrnrlat=ur_lat, **kwargs)  llcrnrlon=-100 urcrnrlon=-30 llcrnrlat=-90 urcrnrlat=-55.0 m = polar_stere(llcrnrlon, urcrnrlon, llcrnrlat, urcrnrlat)  m.drawmeridians(np.arange(0,360,30),labels=[1,1,1,0]) m.drawparallels(np.arange(-90,90,30),labels=[1,1,1,1]) m.drawcoastlines()  plt.show() 

enter image description here


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -