AttributeError:模块“folium”没有属性“Rectangle”

2024-05-12 17:53:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在IBM Watson studio的Python笔记本中使用Folium,尝试了0.5.0和0.11.0版本。folium.Map和folium.Circlemarker工作正常,但folium.Rectangle失败。。。有办法解决这个问题吗?或者用于添加矩形的函数现在有所不同?在标题中生成错误的代码如下

folium.Rectangle(bounds=[[39.78,-105.05],[39.68,-105.05],[39.68,-104.94],[39.78,-104.94]], color='#ff7800', fill=True, fill_color='#ffff00', fill_opacity=0.2).add_to(mapD)

Tags: 函数版本map笔记本watsonfillibmcolor
1条回答
网友
1楼 · 发布于 2024-05-12 17:53:15

首先,请使用folium.__version__再次检查您的对开本版本。(python语言)

根据changelog,可以在0.4.0之后使用folium.CircleMarker

0.4.0

  • PolyLine, Circle and CircleMarker are set to leaflet's defaults and accepted all Path's optional arguments (ocefpaf #683 and #697)

类似地,只能在0.6.0之后使用folium.Rectangle

0.6.0

  • Rectangle and Polygon were renamed and set to leaflet's defaults. Both now accepted all Path's optional arguments (ocefpaf #722)

因此,如果您的folium版本低于0.6.0,您应该使用folium.features.RectangleMarker而不是folium.Rectangle

如果您的folium版本实际上是0.11.0,但仍然不能使用folium.Rectangle,请检查您是否正确导入folium。(使用import folium

相关问题 更多 >