问题描述
当创建有关folium map plotting函数folium.plugins.HeatMap()
内颜色的costum gradient
字典时,lon lat-数据点不会显示在输出图形/地图上。
函数docs可以在here中找到。
这是因为mygradient
-dict传递的是RGBA颜色值,而不是粗体颜色字符串,如“蓝色”、“绿色”等。?
如果我没有得到与实际贴图一起绘制的颜色贴图相适应的颜色范围,我的数据点将始终以默认方式显示(从蓝色到黄色再到红色)
另外,我还想知道如何更改branca.colormap.caption
和索引标签的字体大小和颜色。
它始终以默认字体大小的黑色显示。有时,这在当前地图背景下并不真正可见
预期产出
我的folium.plugins.HeatMap()
的数据点是根据与我通过branca.colormaps创建的相同的colormap绘制的。我认为这可以通过folium.plugins.HeatMap()的梯度参数实现
此外,我想更改branca.colormap.caption的字体大小和-颜色,以便更好地适应实际的卫星地图背景。默认颜色“黑色”部分可理解
打印输出(对开本版本):
“0.10.1”
带有folium和branca实现的Python代码-带有colorscale的热图
# Package importing
import folium
import folium.plugins as fol_plugins
# Instantiate folium base map to plot on
folium_map = folium.Map(location=coord_center_point,
zoom_start=zoom_level,
max_zoom=max_zoom,
tiles=mapbox_tile_URL,
attr='Mapbox')
## Add BRANCA colormap ##
import branca.colormap as branca_folium_cm
colormap = branca_folium_cm.linear.Blues_05.scale(z_min, z_max)
colormap.caption = "Bla bla" # how do I change fontsize and color here?
folium_map.add_child(colormap)
# Prepare gradient dictionary according to the example like {0.4: ‘blue’, 0.65: ‘lime’, 1: ‘red’}
gradient_dict = {}
# Get the index values and colors from the just created branca-colormap
# NOTE: colors are RGBA-vectors, like "(0.9372549019607843, 0.9529411764705882, 1.0, 1.0)":
for ind_val, c in zip(colormap.index, colormap.colors):
# Create gradient dictionary for heatmap on the fly
gradient_dict[ind_val] = c
# Resulting gradient dict in my case:
# {1.4117859851611496e-05: (0.9372549019607843, 0.9529411764705882, 1.0, 1.0), 0.00247235752568163: (0.7411764705882353, 0.8431372549019608, 0.9058823529411765, 1.0), 0.004930597191511649: (0.4196078431372549, 0.6823529411764706, 0.8392156862745098, 1.0), 0.007388836857341667: (0.19215686274509805, 0.5098039215686274, 0.7411764705882353, 1.0), 0.009847076523171685: (0.03137254901960784, 0.3176470588235294, 0.611764705882353, 1.0)}
# Overlay the heatmap data on top of the previously instantiated folium basemap
fol_plugins.HeatMap(data=zip(y, x, z),
name=titlestr,
min_opacity=min_alpha_opacity,
max_zoom=max_zoom,
radius=radius,
gradient=gradient_dict, # insert gradient dict
blur=blur).add_to(folium_map)
我自己找到了一个解决方案,在下面关于GitHub的讨论中也找到了答案: https://github.com/python-visualization/folium/issues/1303#issuecomment-675368594
1) 自己的解决方案
下面将显示每个颜色渐变字典的打印输出
最后,为了完整起见,我将发布以前使用的函数
convert_given_color_to_RGB_RGBA_hex_or_HSV()
的详细信息:2) GitHub的回答
从这里开始,我将在下面提到关键部分:
与我最初的方法不同的是,我直接将颜色元组作为长度为4的元组传递,例如
(0.9372549019607843, 0.9529411764705882, 1.0, 1.0)
。 但正确的形式类似于上面提到的由RGBA值构造的循环中的f字符串:相关问题 更多 >
编程相关推荐