gregwa

FCM 161 - foliumchoro.py

Sep 5th, 2020
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #! /usr/bin/env python
  2. #  -*- coding: utf-8 -*-
  3. # ======================================================
  4. #     foliumchoro.py
  5. #  ------------------------------------------------------
  6. # Created for Full Circle Magazine Issue #
  7. # Written by G.D. Walters
  8. # Copyright (c) 2020 by G.D. Walters
  9. # This source code is released under the MIT License
  10. # ======================================================
  11.  
  12. import folium
  13. import pandas as pd
  14. import webbrowser
  15.  
  16. url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
  17. state_geo = f'{url}/us-states.json'
  18. state_unemployment = f'{url}/US_Unemployment_Oct2012.csv'
  19. state_data = pd.read_csv(state_unemployment)
  20.  
  21. m = folium.Map(location=[48, -102], zoom_start=3)
  22.  
  23. folium.Choropleth(geo_data=state_geo,
  24.                   name='choropleth',
  25.                   data=state_data,
  26.                   columns=['State', 'Unemployment'],
  27.                   key_on='feature.id',
  28.                   fill_color='YlGn',
  29.                   fill_opacity=0.7,
  30.                   line_opacity=0.2,
  31.                   legend_name='Unemployment Rate (%)').add_to(m)
  32.  
  33. folium.LayerControl().add_to(m)
  34.  
  35. output_file = "map2.html"
  36. m.save(output_file)
  37. webbrowser.open(output_file, new=2)
Add Comment
Please, Sign In to add comment