- 积分
- 214
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-11-14
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2020-4-29 15:40:51
|
显示全部楼层
我就是单独画了一个色斑我可以给你我的代码看看
base_colors = np.array([[0, 255, 0], [150, 230, 0], [185, 255, 154]], dtype='f4')
base_colors = base_colors / 255
base_levels = [0, 0.5]
cmap, norm = matplotlib.colors.from_levels_and_colors(base_levels, base_colors, extend='both')
base_lon = np.linspace(113., 123., 100)
base_lat = np.linspace(30., 40., 100)
ff = np.array(Get_MXN_Array_initx(100, 100, 1))
# 绘制图片
im = ax.contourf(base_lon, base_lat, ff[:, :], extend='both', levels=base_levels, cmap=cmap,
transform=ccrs.PlateCarree(),
norm=norm, zorder=1)
shp2clip(im, ax, city, 320000)
def shp2clip(originfig, ax, shpfile, region):
sf = shapefile.Reader(shpfile)
for shape_rec in sf.shapeRecords():
if shape_rec.record[0] == region:
vertices = []
codes = []
pts = shape_rec.shape.points
prt = list(shape_rec.shape.parts) + [len(pts)]
for i in range(len(prt) - 1):
for j in range(prt, prt[i + 1]):
vertices.append((pts[j][0], pts[j][1]))
codes += [Path.MOVETO]
codes += [Path.LINETO] * (prt[i + 1] - prt - 2)
codes += [Path.CLOSEPOLY]
clip = Path(vertices, codes)
clip = PathPatch(clip, transform=ax.transData)
for contour in originfig.collections:
contour.set_clip_path(clip)
return clip
|
|