gpt4 book ai didi

python - basemap : Plot map similar to WRF domain

转载 作者:太空宇宙 更新时间:2023-11-04 02:37:46 24 4
gpt4 key购买 nike

我想绘制一个类似于 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)

如何编辑我的代码以获得相似的图形?

最佳答案

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

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

enter image description here

关于python - basemap : Plot map similar to WRF domain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47437127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com