I'm learning Python applied to data science and I'm trying to create an interactive map of my city, Madrid (Spain), showing the last election results. All I'm doing is in this GitHub link:
https://github.com/BernardoJoseLlamasVerna/Madrid_Elections_2021
You will see draft operations and looking for the best way to represent my data on a map:
I'm following an example found on Internet about Wisconsin elections and fixes perfectly with what I would like to do with my data. I have downloaded it and stored on my repo to show you what I'm trying:
https://github.com/BernardoJoseLlamasVerna/Madrid_Elections_2021/blob/main/maps.ipynb
I've tried to do the same with my data, but nothing appears (even errors). The code is as follows:
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)
I've been analysing wi_geojson comparing between mine and what I copied and they seem to follow the same structure.
**QUESTION: ** anyone could give me a hint about what is wrong with my code, data, etc?
Thank you for your help.
P.D.: if anyone could also post a link with better interactive mapping, I would be so glad.