初学者 python 用户,在使用 Folium 的热图方面取得了一些成功。我正在尝试使用全球恐怖主义数据库作为一些可视化的来源,但我真的很想使用ipywidgets从列表中选择一个特定的恐怖组织来更新我的热图。我已经为 ISIS 构建了一个热图,创建了一个 ipyvuetify 按钮,其中包含我想要比较的组,但是在弄清楚函数和 widgets.link 语法时遇到了麻烦。我真的很感激一些帮助,因为似乎没有任何好的指南(就我的技能水平而言)关于如何做我在这里想做的事情。
import ipyvuetify as v
import ipywidgets as widgets
import folium
from folium import plugins
from folium.plugins import HeatMap as hm
map = folium.Map(location = [25,15], tiles = "cartodbdark_matter", zoom_start = 2)
selected = gtd.loc[gtd['Group'] == 'Islamic State of Iraq and the Levant (ISIL)']
coords = selected[['Latitude','Longitude']]
hm(coords).add_to(map)
terrorists = [
'Taliban',
'Shining Path (SL)',
'Islamic State of Iraq and the Levant (ISIL)',
'Farabundo Marti National Liberation Front (FMLN)',
'Al-Shabaab',
'Irish Republican Army (IRA)',
'Revolutionary Armed Forces of Colombia (FARC)',
'New Peoples Army (NPA)',
'Kurdistan Workers Party (PKK)',
'Boko Haram']
# This is where things go off the rails for me, not exactly sure how to arrange this function
def update(x):
if widget_terrorist_selector.selected is not None:
xmin, xmax = widget_terrorist_selector.selected
widget_terrorist_selector.observe(update,'widget_terrorist_selector')
# The selector here works but I can't figure out how to link it to my map so that it pushes a new set of heatmap coordinates
widget_terrorist_selector = v.Select(label='Choose Option', items=terrorists, v_model=terrorists[0])
widget_terrorist_selector
# This bit keeps throwing a "TypeError: Each object must be HasTraits, not <class 'pandas.core.frame.DataFrame'>"
widgets.link((widget_terrorist_selector,'v_model'),(selected, 'Group'))
提前致谢!