-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix #341: Added highlight function for Choropleth #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
778ce5c
Fixes #341: Added highlight_function functionality for choropleth maps
joshuacano 62a46d3
Fixes #341: Added highlight_function functionality for choropleth maps
joshuacano 65661de
Merge branch 'highlight' of https://github.com/joshuacano/folium into…
joshuacano c6c9f04
Fixes #341: Added Highlight Test
joshuacano 3ff3117
Fixes #341: Added Highlight switch
joshuacano dfa7a44
Fixes #341: Added item to Changes
joshuacano cd90f4c
Fixes #341: Added examples to notebook
joshuacano 8c8c4a8
Fixes #341: Added Highlight Test
joshuacano 5500bbb
Fixes #341: Added Highlight switch
joshuacano 9f5a111
Fixes #341: Added item to Changes
joshuacano 33539fc
Fixes #341: Added examples to notebook
joshuacano 01fb74c
Merge branch 'highlight' of https://github.com/joshuacano/folium into…
joshuacano e25111c
Merge remote-tracking branch 'upstream/master'
joshuacano b0120e8
Fixes #341: Added Highlight Test
joshuacano b0493c4
Fixes #341: Added Highlight switch
joshuacano 203a5d0
Fixes #341: Added item to Changes
joshuacano 4be246f
Fixes #341: Added examples to notebook
joshuacano 8ad8ff0
Fixes #341: Added Highlight Test
joshuacano 5574b10
Merge branch 'highlight' of https://github.com/joshuacano/folium into…
joshuacano de57eac
Fixes #341: Moved example to renamed file
joshuacano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 1, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -23,7 +23,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 2, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -50,7 +50,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 3, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -77,7 +77,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 4, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -106,7 +106,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 5, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -137,7 +137,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 6, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -165,10 +165,11 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 7, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| <<<<<<< HEAD | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we have a conflict remaining here. Don't worry I will fix this in another PR. |
||
| "outputs": [ | ||
| { | ||
| "data": { | ||
|
|
@@ -194,7 +195,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 8, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -229,7 +230,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 9, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -322,7 +323,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 10, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -367,7 +368,31 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 11, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "state_geo = r'us-states.json'\n", | ||
| "state_unemployment = r'US_Unemployment_Oct2012.csv'\n", | ||
| "\n", | ||
| "state_data = pd.read_csv(state_unemployment)\n", | ||
| "\n", | ||
| "#Enable Highlighting function, to allow hover highlight function\n", | ||
| "states = folium.Map(location=[48, -102], zoom_start=3)\n", | ||
| "states.choropleth(geo_path=state_geo, data=state_data,\n", | ||
| " columns=['State', 'Unemployment'],\n", | ||
| " key_on='feature.id',\n", | ||
| " fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,\n", | ||
| " legend_name='Unemployment Rate (%)', highlight=True)\n", | ||
| "\n", | ||
| "states" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -394,13 +419,13 @@ | |
| " key_on='feature.id',\n", | ||
| " fill_color='BuPu', fill_opacity=0.7, line_opacity=0.5,\n", | ||
| " legend_name='Unemployment Rate (%)',\n", | ||
| " reset=True)\n", | ||
| " reset=True, highli)\n", | ||
| "states2" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 12, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -453,7 +478,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 13, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
@@ -497,7 +522,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 14, | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,15 +22,13 @@ | |
| ClickForMarker, TopoJson, PolyLine, MultiPolyLine, | ||
| ) | ||
|
|
||
|
|
||
| def initialize_notebook(): | ||
| """Initialize the IPython notebook display elements.""" | ||
| warnings.warn("%s is deprecated and no longer required." % | ||
| ("initialize_notebook",), | ||
| FutureWarning, stacklevel=2) | ||
| pass | ||
|
|
||
|
|
||
| class Map(LegacyMap): | ||
| """Create a Map with Folium and Leaflet.js | ||
|
|
||
|
|
@@ -510,7 +508,8 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |
| data=None, columns=None, key_on=None, threshold_scale=None, | ||
| fill_color='blue', fill_opacity=0.6, line_color='black', | ||
| line_weight=1, line_opacity=1, legend_name="", | ||
| topojson=None, reset=False, smooth_factor=None): | ||
| topojson=None, reset=False, smooth_factor=None, | ||
| highlight=None): | ||
| """ | ||
| Apply a GeoJSON overlay to the map. | ||
|
|
||
|
|
@@ -582,6 +581,8 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |
| How much to simplify the polyline on each zoom level. More means | ||
| better performance and smoother look, and less means more accurate | ||
| representation. Leaflet defaults to 1.0. | ||
| highlight: boolean, default False | ||
| Enable highlight functionality when hovering over a GeoJSON area. | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -598,6 +599,12 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json', | |
| ... threshold_scale=[0, 20, 30, 40, 50, 60]) | ||
| >>> m.choropleth(geo_path='countries.json', | ||
| ... topojson='objects.countries') | ||
| >>> m.choropleth(geo_path='geo.json', data=df, | ||
| ... columns=['Data 1', 'Data 2'], | ||
| ... key_on='feature.properties.myvalue', | ||
| ... fill_color='PuBu', | ||
| ... threshold_scale=[0, 20, 30, 40, 50, 60], | ||
| ... highlight=True) | ||
|
|
||
| """ | ||
| if threshold_scale and len(threshold_scale) > 6: | ||
|
|
@@ -679,6 +686,13 @@ def style_function(x): | |
| "fillColor": color_scale_fun(x) | ||
| } | ||
|
|
||
|
|
||
| def highlight_function(x): | ||
| return { | ||
| "weight": line_weight + 2, | ||
| "fillOpacity": fill_opacity + .2 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These looks like sensible defaults. Thanks! |
||
| } | ||
|
|
||
| if topojson: | ||
| geo_json = TopoJson( | ||
| geo_data, | ||
|
|
@@ -689,7 +703,8 @@ def style_function(x): | |
| geo_json = GeoJson( | ||
| geo_data, | ||
| style_function=style_function, | ||
| smooth_factor=smooth_factor) | ||
| smooth_factor=smooth_factor, | ||
| highlight_function=highlight_function if highlight else None) | ||
|
|
||
| self.add_child(geo_json) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this cell was not executed.