Python 如何在带有对开本的html上添加图例?
我使用这段代码在html上生成坐标,但是我想在这个html中添加一个图例,我应该怎么做Python 如何在带有对开本的html上添加图例?,python,html,folium,Python,Html,Folium,我使用这段代码在html上生成坐标,但是我想在这个html中添加一个图例,我应该怎么做 import folium m = folium.Map(location=[45.5236, -122.6750]) html = 'Hello' popup=folium.Popup(html,show=True,max_width=400) folium.Circle( location = [45.372, -122.6972], radius = 100, popup=po
import folium
m = folium.Map(location=[45.5236, -122.6750])
html = 'Hello'
popup=folium.Popup(html,show=True,max_width=400)
folium.Circle(
location = [45.372, -122.6972],
radius = 100,
popup=popup,
color='red',
fill=True,
fill_opacity=0.1
).add_to(m)
m.save(r'E:/test.html')
我想要这样的效果:
正如r初学者所说
我用这个来添加图例
from branca.element import Template, MacroElement
import folium
template = """
{% macro html(this, kwargs) %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Draggable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#maplegend" ).draggable({
start: function (event, ui) {
$(this).css({
right: "auto",
top: "auto",
bottom: "auto"
});
}
});
});
</script>
</head>
<body>
<div id='maplegend' class='maplegend'
style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
<div class='legend-title'>Legend (draggable!)</div>
<div class='legend-scale'>
<ul class='legend-labels'>
<li><span style='background:red;opacity:0.7;'></span>Big</li>
<li><span style='background:orange;opacity:0.7;'></span>Medium</li>
<li><span style='background:green;opacity:0.7;'></span>Small</li>
</ul>
</div>
</div>
</body>
</html>
<style type='text/css'>
.maplegend .legend-title {
text-align: left;
margin-bottom: 5px;
font-weight: bold;
font-size: 90%;
}
.maplegend .legend-scale ul {
margin: 0;
margin-bottom: 5px;
padding: 0;
float: left;
list-style: none;
}
.maplegend .legend-scale ul li {
font-size: 80%;
list-style: none;
margin-left: 0;
line-height: 18px;
margin-bottom: 2px;
}
.maplegend ul.legend-labels li span {
display: block;
float: left;
height: 16px;
width: 30px;
margin-right: 5px;
margin-left: 0;
border: 1px solid #999;
}
.maplegend .legend-source {
font-size: 80%;
color: #777;
clear: both;
}
.maplegend a {
color: #777;
}
</style>
{% endmacro %}"""
m = folium.Map(location=[45.5236, -122.6750])
html = 'Hello'
popup=folium.Popup(html,show=True,max_width=400)
folium.Circle(
location = [45.372, -122.6972],
radius = 100,
popup=popup,
color='red',
fill=True,
fill_opacity=0.1
).add_to(m)
macro = MacroElement()
macro._template = Template(template)
m.get_root().add_child(macro)
url = 'myTest.html'
m.save(url)
来自branca.element导入模板,宏元素
进口叶
模板=“”“
{%macro-html(this,kwargs)%}
jQuery UI可拖动-默认功能
$(函数(){
$(“#maplegend”).可拖动({
开始:功能(事件、用户界面){
$(this.css)({
右:“自动”,
顶部:“自动”,
底部:“自动”
});
}
});
});
图例(可拖动!)
- 大的
- 中等
- 小的
.maplegend.传奇标题{
文本对齐:左对齐;
边缘底部:5px;
字体大小:粗体;
字体大小:90%;
}
.maplegend.图例比例ul{
保证金:0;
边缘底部:5px;
填充:0;
浮动:左;
列表样式:无;
}
.maplegend.legend scale ul li{
字号:80%;
列表样式:无;
左边距:0;
线高:18px;
边缘底部:2px;
}
.maplegend ul.legend-labels li span{
显示:块;
浮动:左;
高度:16px;
宽度:30px;
右边距:5px;
左边距:0;
边框:1px实心#999;
}
.maplegend.图例来源{
字号:80%;
颜色:#777;
明确:两者皆有;
}
梅普根德先生{
颜色:#777;
}
{%endmacro%}”“”
m=folium.Map(位置=[45.5236,-122.6750])
html='Hello'
popup=folium.popup(html,show=True,最大宽度=400)
圆叶(
位置=[45.372,-122.6972],
半径=100,
弹出=弹出,
颜色='红色',
填充=真,
填充不透明度=0.1
).将_添加到(m)
宏=宏元素()
宏。\u模板=模板(模板)
m、 获取\根()。添加\子项(宏)
url='myTest.html'
m、 保存(url)
我发现这很有帮助,我使用了你提到的例子。屏幕右侧将生成一个颜色栏。虽然可以显示文本,但颜色栏不是我想要的,文本显示在右上角。我认为最后一个示例会有所帮助。你回复了哪一个?我使用import branca
colormap=branca.colormap.linear.YlOrRd\u 09.scale()
colormap.caption='the legend'