python - pyplot.contourf 和 branca 颜色图在 folium 中不显示相同的颜色
问题描述
我正在尝试contourf plot
在 Folium 地图的代码片段中显示如下所示。
我可以很好地看到填充的等高线图。另外,我在这一行添加了一个颜色完全相同的颜色branca
条:
bmap = branca.colormap.LinearColormap(colorl, vmin=levs[0],
vmax=levs[-1]).to_step(len(levs),index=levs)
geojsonf = geojsoncontour.contourf_to_geojson(
contourf=pcontf,
min_angle_deg=3.0,
ndigits=5,
stroke_width=1,
fill_opacity=0.9)
正如您在输出图像中看到的,颜色不匹配。
我怀疑我用于等高线图的不透明度可能在这里起作用,但改变不透明度并不能使它变得更好。
我还尝试用相同的颜色制作圆形标记(此处未显示),但仍然没有运气。我无法让 pyplot 颜色匹配。
非常感谢任何建议。还有没有更好的方法来完成相同的任务?我基本上有一个 2D NumPy 数组,其值范围从-50 to 50
重新投影的 lat-lon 网格。我需要能够在栏中显示阴影轮廓和相关值。
fig = plt.figure(figsize=[10, 15], dpi=None)
ax = fig.subplots()
jet =plt.get_cmap('jet')
clevs= np.array(levs)
cnorm = plt.Normalize(vmin=levs[0],vmax=levs[-1])
clevels = [levs[0]] + list(0.5*(clevs[1:]+clevs[:-1])) + [levs[-1]]
colors=jet(cnorm(clevels))
colorsm = color.ListedColormap(colors)
pcontf = ax.contourf(lons,lats,data,levels=levs,cmap=colorsm)
mapa = folium.Map([np.mean(lats), np.mean(lons)], zoom_start=10,tiles='Stamen Terrain')
colorl = []
for i,val in enumerate(colors):
carr= colors[i-1]
ccol = (carr[1],carr[2],carr[3])
colorl.insert(i,ccol)
bmap = branca.colormap.LinearColormap(colorl, vmin=levs[0],
vmax=levs[-1]).to_step(len(levs),index=levs)
geojsonf = geojsoncontour.contourf_to_geojson(
contourf=pcontf,
min_angle_deg=3.0,
ndigits=5,
stroke_width=1,
fill_opacity=0.9)
folium.GeoJson(
geojsonf,
style_function=lambda x: {
'color': x['properties']['stroke'],
'weight': x['properties']['stroke-width'],
'fillColor': x['properties']['fill'],
'opacity': 0.9,
}).add_to(mapa)
bmap.add_to(mapa)
解决方案
推荐阅读
- typescript - 是否可以动态地在泛型类型中使用 import()
- java - 在 Spring Boot 中编辑时选择多选中的项目
- dynamics-crm - 如何获取不在特定队列/团队中的用户?
- highcharts - Highcharts .Net(最新)YAxis.GridLineDashStyle Hashtable 不适用于客户端库
- perl - Perl - 如何从数组 M 维计算 N 个字节的 CRC16(使用 N
我需要计算从大小为 M 的二进制文件(一对 Kb,与我的范围不太相关)中提取的 N 字节(示例中为 5,为简单起见)的 CRC16。
printf "offset\tvalue\tcrc16\n"; #Read N bytes from file and copy in the container
- r - 子集,未按预期选择
- spring-cloud-dataflow - Spring Cloud 数据流:错误 org.springframework.dao.InvalidDataAccessResourceUsageException
- next.js - NextJS 语言环境随动态路由变化
- c++ - 如何使用 ESPAsyncTCP 库在 ESP8266 上设置 TCP 服务器以及指针如何工作
- amazon-athena - Athena Engine V1 到 V2 在结构列上变慢