如何在 folium 贴图中添加颜色贴图的背景颜色

A. *_*ari 4 html python background-color colormap folium

我正在使用基于 json 文件创建的folium地图。我使用branca.colormap添加了一个颜色图,我想添加一个背景颜色,因为生成的颜色图可能有一些颜色与它后面的地图,这会导致可视化问题。

我可以将此颜色图添加到框架中还是仅添加背景颜色?

Adr*_*ing 5

这是一个相当老套的解决方案,但它有效:

通过函数打开 folium 生成的 html 文件map_instance.save('map.html')

通过搜索来查找生成传单控件的行.append("svg")

在其后面插入此代码片段,确保变量名称正确(即从代码中的变量复制随机生成的 id)

color_map_<random_generated_id>.svg.append("rect")
    .attr("width", "100%")
    .attr("height", "100%")
    .attr("fill", "white")
    .attr("opacity", "0.8");
Run Code Online (Sandbox Code Playgroud)

您还可以通过更改变量中的 leaflet-control 位置属性来定位图例color_map_<random_generated_id>.legend。在我的例子中我使用L.control({position: 'bottomleft'});

图片示例