本文整理汇总了Python中mpl_toolkits.basemap.Basemap.artists方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.artists方法的具体用法?Python Basemap.artists怎么用?Python Basemap.artists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.artists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_basemap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import artists [as 别名]
def build_basemap(lower_left=[-20,-30],upper_right=[20,10],ax=None,proj='cyl',profile=None,larger=True):
"""
First try at a building of the basemap with a 'stere' projection
Must put in the values of the lower left corner and upper right corner (lon and lat)
Defaults to draw 8 meridians and parallels
Modified: Samuel LeBlanc, 2015-09-15, NASA Ames
- added profile keyword that contains the basemap profile dict for plotting the corners
- added programatic determination of basemap parallels and meridians
Modified: Samuel LeBlanc, 2016-07-17, Santa Cruz, CA
- added plotting of larger region, which is then resized, to have space to pan and zoom.
"""
from map_interactive import pll
if profile:
upper_right = [pll(profile['Lon_range'][1]),pll(profile['Lat_range'][1])]
lower_left = [pll(profile['Lon_range'][0]),pll(profile['Lat_range'][0])]
if larger:
dp = 30
else:
dp = 0
try:
import cPickle as pickle
m = pickle.load(open('map_{}.pkl'.format(profile['Campaign']),'rb'))
#print 'doing it pickle style'
m.ax = ax
except:
if larger:
dp = 30
else:
dp = 0
m = Basemap(projection=proj,lon_0=(upper_right[0]+lower_left[0])/2.0,lat_0=(upper_right[1]+lower_left[1])/2.0,
llcrnrlon=lower_left[0]-dp, llcrnrlat=lower_left[1]-dp,
urcrnrlon=upper_right[0]+dp, urcrnrlat=upper_right[1]+dp,resolution='i',ax=ax)
m.artists = []
m.drawcoastlines()
#m.fillcontinents(color='#AAAAAA')
m.drawstates()
m.drawcountries()
m.large = True
round_to_5 = lambda x:(int(x/5)+1)*5
round_to_2 = lambda x:(int(x/2)+1)*2
if (upper_right[0]-lower_left[0])<20.0:
mer = np.arange(round_to_2(lower_left[0]-dp),round_to_2(upper_right[0]+dp)+2,2)
difx = 0.2
m.large = False
else:
mer = np.arange(round_to_5(lower_left[0]-dp),round_to_5(upper_right[0]+dp)+5,5)
difx = 1.0
if (upper_right[1]-lower_left[1])<20.0:
par = np.arange(round_to_2(lower_left[1]-dp),round_to_2(upper_right[1]+dp)+2,2)
dify = 0.2
m.large = False
else:
par = np.arange(round_to_5(lower_left[1]-dp),round_to_5(upper_right[1]+dp)+5,5)
dify = 1.0
if ax:
ax.set_xlim(lower_left[0],upper_right[0])
ax.set_ylim(lower_left[1],upper_right[1])
m.artists.append(m.drawmeridians(mer,labels=[0,0,0,1]))
m.artists.append(m.drawparallels(par,labels=[1,0,0,0]))
# move the meridian labels to a proper position
for aa in m.artists[0].keys():
try:
m.artists[0][aa][1][0].set_position((m.artists[0][aa][1][0].get_position()[0],lower_left[1]-difx))
except:
pass
# move the parallels labels to a proper position
for aa in m.artists[1].keys():
try:
m.artists[1][aa][1][0].set_position((lower_left[0]-dify,m.artists[1][aa][1][0].get_position()[1]))
except:
pass
#import pdb; pdb.set_trace()
if ax:
try:
ax.figure.show()
except:
try:
ax.figure.canvas.draw()
except:
pass
return m