底图:绘制类似于WRF域的地图

时间:2017-11-22 14:27:35

标签: python matplotlib-basemap

我想绘制一个类似于WRF域的数字,如The following figure,只有矩形框,在域的框架内没有任何颜色。但是,我最接近的是

This figure

使用以下代码: -

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import pylab as P

def draw_screen_poly( lats, lons, m):
    x, y = m( lons, lats )
    xy = zip(x,y)
    poly = Polygon( xy,alpha=0.1,edgecolor='k',linewidth=1 )
    plt.gca().add_patch(poly)

lats = [ 26.1238,29.2537,29.2537,26.1238 ]
lons = [82.5228,82.5228, 87.2772,87.2772 ]

m = Basemap(llcrnrlon=80,llcrnrlat=25,urcrnrlon=90,urcrnrlat=30,
              projection='merc', lat_1=27.7,lat_2=60.,lat_0=27.69998,lon_0=85.3,resolution="h")
m.drawcoastlines()
m.drawmapboundary()
m.drawcountries(linewidth=1,color='k')
m.fillcontinents(color='g',lake_color='aqua')
parallels = np.arange(0.,90,1.)
m.drawparallels(parallels,labels=[1,0,0,0],color="gray",fontsize=10)
draw_screen_poly( lats, lons, m )
meridians = np.arange(0.,180.,1.)
m.drawmeridians(meridians,labels=[0,0,0,1],color="gray",fontsize=10)
fig = P.gcf()
P.show()
pngfile = "map_new_domain.pdf".format("avg")
fig.savefig(pngfile)

如何编辑我的代码以获得相似的数字?

1 个答案:

答案 0 :(得分:1)

您需要设置Polygon对象的facecolor参数,这将设置填充颜色。如果你想要一条没有填充的实线,我也删除了不需要的alpha。

poly = Polygon( xy, edgecolor='k', linewidth=2, facecolor='none')

enter image description here