Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- from bokeh.io import show, output_notebook
- from bokeh.models import GeoJSONDataSource, LinearColorMapper
- import geopandas as gpd
- from bokeh.palettes import Viridis6 as palette
- from bokeh.plotting import figure
- output_notebook()
- #obtain countries shapes
- world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
- europe = (world.loc[world['continent'] == 'Europe'])
- # Normal Dataframe (non-geo)
- df = pd.DataFrame(data=europe.name.str.len().values, index=europe.index, columns=['name_length'])
- europe = europe.merge(df, left_index=True, right_index=True)
- geo_source = GeoJSONDataSource(geojson=europe.to_json())
- p = figure(title="Europe", x_range=(-30,60), y_range=(30,85))
- p.patches('xs', 'ys', fill_alpha=0.7,
- fill_color={'field': 'name_length', 'transform': LinearColorMapper(palette=palette)},
- line_color='black', line_width=0.5, source=geo_source)
- show(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement