[英]Problems plotting interactive maps with Python
我正在學習 Python 應用於數據科學,我正在嘗試創建我的城市馬德里(西班牙)的交互式 map,顯示上次選舉結果。 我所做的就是在這個 GitHub 鏈接中:
https://github.com/BernardoJoseLlamasVerna/Madrid_Elections_2021
您將看到草稿操作並尋找在 map 上表示我的數據的最佳方式:
我正在按照在 Inte.net 上找到的關於威斯康星州選舉的示例進行操作,並完美地修復了我想對我的數據所做的事情。 我已將其下載並存儲在我的存儲庫中以向您展示我正在嘗試的內容:
https://github.com/BernardoJoseLlamasVerna/Madrid_Elections_2021/blob/main/maps.ipynb
我試圖對我的數據做同樣的事情,但什么也沒有出現(甚至是錯誤)。 代碼如下:
from bokeh.io import output_notebook
from bokeh.plotting import figure, ColumnDataSource
from bokeh.io import output_notebook, show, output_file
from bokeh.plotting import figure
from bokeh.models import GeoJSONDataSource, LinearColorMapper, ColorBar, HoverTool
from bokeh.palettes import brewer
output_notebook()
import json
# res_w_states["clinton_share"] = res_w_states["clinton"] / res_w_states["total"]
#Convert data to geojson for bokeh
wi_geojson=GeoJSONDataSource(geojson=data.to_json())
color_mapper = LinearColorMapper(palette = brewer['RdBu'][10], low = 0, high = 1)
color_bar = ColorBar(color_mapper=color_mapper, label_standoff=8,width = 500, height = 20,
border_line_color=None,location = (0,0), orientation = 'horizontal')
hover = HoverTool(tooltips = [ ('Municipio','@Municipio'),('P.P.', '@P.P.'),
('P.S.O.E.','@P.S.O.E.'),
('Votos Totales','@Votos Totales')])
p = figure(title="Elecciones Madrid 2021", tools=[hover])
p.patches("xs","ys",source=wi_geojson,
fill_color = {'field' :'P.P.', 'transform' : color_mapper})
p.add_layout(color_bar, 'below')
show(p)
我一直在分析 wi_geojson,比較我的和我復制的,它們似乎遵循相同的結構。
**問題:** 任何人都可以給我提示我的代碼、數據等有什么問題嗎?
謝謝您的幫助。
PD:如果有人也可以發布具有更好的交互式地圖的鏈接,我會很高興。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.