pyplot.contourf和branca颜色图在大叶中显示的颜色不同

问题描述

我正在尝试显示一个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)

如您在输出图像中看到的,颜色不匹配。

enter image description here

我怀疑我在等高线图中使用的不透明度可能在这里起作用,但是更改不透明度并不能使其变得更好。

我还尝试过用相同的颜色但仍然没有运气来制作圆形标记(此处未显示)。我无法获得匹配的pyplot颜色。

任何建议都将不胜感激。还有没有更好的方法来完成相同的任务?我基本上有一个二维NumPy数组,其值在重新投影的经纬网格上的范围为-50 to 50。我需要能够在栏中显示阴影轮廓和相关值。

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,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)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)