SHARE
TWEET

Untitled

a guest Jun 27th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import numpy as np
  3. from bokeh.io import show, output_notebook
  4. from bokeh.models import GeoJSONDataSource, LinearColorMapper
  5.  
  6. import geopandas as gpd
  7. from bokeh.palettes import Viridis6 as palette
  8. from bokeh.plotting import figure
  9.  
  10. output_notebook()
  11.  
  12. #obtain countries shapes
  13. world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
  14. europe = (world.loc[world['continent'] == 'Europe'])
  15.  
  16. # Normal Dataframe (non-geo)
  17. df = pd.DataFrame(data=europe.name.str.len().values, index=europe.index, columns=['name_length'])
  18. europe = europe.merge(df, left_index=True, right_index=True)
  19.  
  20. geo_source = GeoJSONDataSource(geojson=europe.to_json())
  21.  
  22. p = figure(title="Europe", x_range=(-30,60), y_range=(30,85))
  23.  
  24. p.patches('xs', 'ys', fill_alpha=0.7,
  25.       fill_color={'field': 'name_length', 'transform': LinearColorMapper(palette=palette)},
  26.       line_color='black', line_width=0.5, source=geo_source)
  27.  
  28.  
  29.  
  30. show(p)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top