python-visualization / folium Goto Github PK
View Code? Open in Web Editor NEWPython Data. Leaflet.js Maps.
Home Page: https://python-visualization.github.io/folium/
License: MIT License
Python Data. Leaflet.js Maps.
Home Page: https://python-visualization.github.io/folium/
License: MIT License
Is there a way to save the image as PDF or PNG?
I am hoping to batch a set of datasets to create a set of image sequence for creating a video.
Steps: create a map with location, add a few markers, but then take the center of all the markers, and recenter the map?
map = folium.Map(location=[lat,lon],zoom_start=15)
#do this a few times
map.circle_marker(location=[lat,lon],radius=acc,popup=creature,line_color='#3186cc',fill_color='#3186cc')
lat_mid = (lat_min+lat_max)/2
lon_mid = (lon_min+lon_max)/2
print('{0},{1}'.format(lat_mid,lon_mid))
#set to middle point
#how do i reset the location?
#map_rr ____?____(location=[lat_mid,lon_mid],zoom_start=14)
I get an import error on py 3.3 on a VM. Issue with my VM config, in which case, any idea of the fix? Or a wider issue?
ImportError Traceback (most recent call last)
<ipython-input-5-af6e4f19ef00> in <module>()
----> 1 import folium
/usr/local/lib/python3.3/dist-packages/folium/__init__.py in <module>()
1 # -*- coding: utf-8 -*-
----> 2 from folium import Map
ImportError: cannot import name Map
For Choropleth maps, if the GeoJSON and JSON data do not match, the color defaults to the highest in the scale. It would be preferable for it to default to white, in order to recognize that the value is missing.
This is an awesome library! I noticed that it's still using Leaflet 0.5, though, which breaks compatibility with a number of modern plugins -- and that the most recent commit is three months ago.
I'd be more than happy to submit a PR updating, I just wanted to make sure you're still interested in maintaining the library :)
I am interested in whether folium would be able to use leaflet plugins http://leafletjs.com/plugins.html and what would be involved?
Propose set default height and width as 100%
. It useful when I just create map sample and it will take all size of display on devices with any sizes.
Depend from #22.
folium maps do not work properly when hosted in a https protocol:
https://ocefpaf.github.io/python4oceanographers/blog/2015/02/02/cartopy_folium_shapefile
http://ocefpaf.github.io/python4oceanographers/blog/2015/02/02/cartopy_folium_shapefile
Lets create an example where we interact with the generated map with Flask as backend server. The idea is demonstrate example where you could seamlessly modify the map information via provided user interface,
Say we create a Choropleth of US state as GeoJson
a) Create a range slider to select a state from 1 to 50, the selected state will get highlighted with a different color.
b) Simulate a value associated with each state say GDP or population. Create a button named simulate which generates random populations for each state. Each time a user clicks this button a new random distribution of say population is generated and the map is updated with a color scale.
Hello developers,
I've been starting to use foluim to produce leaflet.js maps from geographical data using python and pandas dataframe.
I've noticed that when trying to use the polygon markers, and export to html via map.create_map, the 'http:' prefix is missing on the head of the html file.
While trying to open the html file separately or by an iframe, the javascript does not find this urls locally (as it prepends with 'file:') on the bootstrap and markercluster (js and css files).
I don't know if this is the expected behavior, but anyway is reported.
Input on python (from polygon marker example)
import folium
map_5 = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
map_5.polygon_marker(location=[45.5012, -122.6655], popup='Ross Island Bridge',
fill_color='#132b5e', num_sides=3, radius=10)
map_5.polygon_marker(location=[45.5132, -122.6708], popup='Hawthorne Bridge',
fill_color='#45647d', num_sides=4, radius=10)
map_5.polygon_marker(location=[45.5275, -122.6692], popup='Steel Bridge',
fill_color='#769d96', num_sides=6, radius=10)
map_5.polygon_marker(location=[45.5318, -122.6745], popup='Broadway Bridge',
fill_color='#769d96', num_sides=8, radius=10)
map_5.create_map(path='bridges.html')
bridges.html file output header:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css">
<script src="https://rawgithub.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>
<link rel="stylesheet" href="http://birdage.github.io/Leaflet.awesome-markers/dist/leaflet.awesome.rotate.css">
<script src="https://wrobstory.github.io/leaflet-dvf/leaflet-dvf.markers.min.js"></script>
Thanks and best regards,
Marcelo
Enhancement request: It would be great to have an option added to the various _marker
functions to add markers to specific layers that can then be shown or hidden on the final map (like this).
id like to see a time slider widget added to the map interface for makers that move, id like to see this also applied to data layers so a user can step through time.
something like this:
http://recallfx.github.io/LeafletPlayback/examples/example_2.html#
http://recallfx.github.io/LeafletPlayback/examples/example_0.html
If I take the
import folium
folium.initialize_notebook()
route to using folium in an IPython notebook, if I create a map and preview it in one cell, then annotate the map and try to view it from another cell, I get the error:
Javascript error adding output!
Error: Map container is already initialized.
However, if I use the old inline_map/iframe approach, as in http://nbviewer.ipython.org/gist/psychemedia/c1ac132946fa120cad91 for example, I can drop iframes containing increasingly layered maps into multiple cells.
In the notebook context used for investigation or teaching purposes, it would be handy to be able to build up maps a cell at a time, previewing them after each cell?
creating a marker with vincent popups is great but at the minute when you click a marker and view the popup and plot/data, close the popup and try to view it again nothing is shown
Hi, I installed Folium and all the dependencies (I'm pretty sure!). It works fine when running examples by themselves but I'm getting the following error when running a python notebook in the examples folder.
https://github.com/wrobstory/folium/blob/f7194ad976bbcccf82c258b2f37b53f1d4ed22c9/folium/folium.py#L24
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-eab1a1a74772> in <module>()
2 import pandas as pd
3
----> 4 folium.initialize_notebook()
AttributeError: 'module' object has no attribute 'initialize_notebook'
I traced the function and found it thinks I didnt have utilities
, but it shoulda been imported right? https://github.com/wrobstory/folium/blob/f7194ad976bbcccf82c258b2f37b53f1d4ed22c9/folium/utilities.py
update:
i just commented out the folium.initialize_notebook()
line, and then I notice that osm.html
is being generated in the folium
folder (where I ran ipython notebook
). Thanks, nvm about this issue, unless you want to chime in about how to embed the map in the notebook :) because right now it only says <folium.folium.Map at 0x7f3aa3351b90>
.
I'm kinda new to folium, so I may have just missed something obvious, but I haven't been able to find a folium feature to resize the map.
I could change the javascript for the map, but as I've got about 10 different maps (and more to come) that are all being generated automatically using python, this doesn't seem like a good solution.
I'd ideally want the map to dynamically respond based on the window size.
Is this already possible without changing the javascript? If not, it'd be a great feature.
When I run the Marker examples on https://github.com/python-visualization/folium, the html which is output has some malformed URLs in the head. For example, in the “mthood.html” example, the “http:” is missing in the following URLs:
href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"
href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"
src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"
href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"
href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css"
href="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css"
src="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"
src="//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"
After I manually edit the html to include “http:" at the beginning of the URLs above, everything is happy. Same for the iconTest.html example.
I am running folium v0.1.3 and python3.
I am using iPython notebook and Firefox on a Mac, although I don’t see how those would affect the html folium outputs.
Do I need to set some kind of folium config variable? Or is this a bug? Thanks!
PS The choropleth example “us_states.html” from https://github.com/python-visualization/folium also doesn’t work for me, but it’s not due to missing “http:” anywhere. I haven’t yet tracked down the cause, but what I get is a map of the US, a colorbar, but no unemployment data.
Hi Rob,
Another great Python app you're building. Here's a feature request for you: Add polyline markers to Folium, so that folks can draw lines between dots on a map.
Hi,
I wanted to create simple lines and found support for that on the master
branch on Github but when I installed it with pip
there was no support for Map.line
.
I used the zip
file from Github to install it and worked perfectly. Just wanted to let you know that this happened.
PS. pip freeze
showed both as 0.1.2
.
Great tool. Thanks!
First and foremost, congrats for an extremely useful package! I just started playing with it, and I love it.
I am trying to visualize data at the zip code level (US zip codes), but don't know how to proceed.
Say for example that I have:
zip code value
02138 0.8
30005 0.9
98104 0.3
...
Is there any way to visualize this data in Folium? Do I need to create a Geo or Topo JSON with arcs for those zip codes? Is such data perhaps available already somewhere?
If creating a Geo or Topo JSON file at the zip code level is unfeasible for some reason (or too much data to visualize), does anyone have recommendations about how to proceed about mapping zip codes to US counties? ( I could try to plot the average value above within each county)
In map.geo_json
the parameter geo_path
is supposed to be a filename which containes the geojson to be shown. Because of that, it is impossible to visualize geojson objects that are not contained in files. I realized this as I was trying to view several GPS trajectories not contained in files.
I propose to change this behavior so that geo_json accepts also geojson strings or fileobjects. In this way backwards compatibility is maintened and higher flexibility is achieved. I can take care of the implementation.
What do you think about this?
I'm using the library but encountered some problems with german umlauts. Could you please add a the encoding to the head section of the html templates to fix character encoding issues?
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
Best Regards,
Simon Breuss
@ocefpaf as discussed i think we need a change log for the versions, and we could do with updating the readme links and content.
As far as I can tell, none of the examples in folium_examples.ipynb work in IPython/Jupyter Notebook 3.0.0.
I'm going to have to sort this one out soon.
I was wondering if it is possible to add multiple layers into you fantastic library by doing something similar to below?
var watercolor = new L.StamenTileLayer("watercolor");
var cloudmade = new L.TileLayer("http://{s}.tile.cloudmade.com//{z}/{x}/{y}.png")
var rain = new L.tileLayer.wms("http://localhost:8080/geoserver/test/wms", {
layers: 'wrc:data',
format: 'image/png',
transparent: true
});
var texture = new L.tileLayer.wms("http://localhost:8080/geoserver/test/wms", {
layers: 'wrc:TEXTURED_LANDCOVER_20M',
format: 'image/jpg',
transparent: true
});
var map = new L.Map("map", {
center: [-37.9021, 175.1725],
zoom: 8,
})
.addLayer(layer);
var baseMaps = {
"cloudmade": cloudmade,
"watercolor": watercolor,
};
var overlayMaps = {
"test": texture,
"rain": rain,
};
L.control.layers(baseMaps, overlayMaps).addTo(map);
Colormap is not being applied to the geojson? the polygons keep appearing black, although legend shows the correct color bar.
print my_data
map_1 = folium.Map(location=[cy, cx], zoom_start=8,)
#add origin marker
#map_1.polygon_marker(location=[cy,cx], popup=str(r))
map_1.geo_json(geo_path='p.json', data=my_data, data_out='data.json',
columns=['id', 'value'],
threshold_scale=[0.0, 0.25, 0.5, 1.0],
key_on='feature.id',
fill_color='YlGn', fill_opacity=1.0, line_opacity=0.2, reset=True)
map_1.create_map(path=path, plugin_data_out=True)
Print of my_data
id value
0 1793 0.162983
1 1796 0.247965
2 1797 0.456300
3 1798 0.840878
4 1799 0.612632
5 1800 0.540876
6 1801 0.792621
7 1802 0.302303
8 1803 0.534493
9 1804 0.306899
10 1805 0.208577
11 1806 0.904390
12 1807 0.127597
13 1808 0.567768
14 1809 0.021931
15 1810 0.084022
is there a way at present to zoom and fit the map to a bounding box?
i see there is a way to change the tileset/tile layer, is there any way to add wms layer support? WMS is currently supported in leaflet
this might go hand in hand with #10
http://gis.stackexchange.com/questions/73967/combine-leaflet-with-geoserver-wms-map
We have some code that depends on the current version of folium and would like to make a conda module for our community. It would be nice if it had a version number -- any interest in tagging the current release here on github?
Non integer values doesn't accessed with Map
constructor. For example 100%
.
I was wondering, even though I like the JSON approach (and GeoJSONs are a far more elegant solution than what I am about to propose!), why not add a functionality to modify the width and height of the text popup and let the user add HTML graphics in folium? Both bokeh and mpl3d can save the plots as HTML.
I already toyed with the idea here:
http://nbviewer.ipython.org/github/ocefpaf/secoora/blob/mpld3/notebooks/sandbox/test_mpld3.ipynb
But my knowledge of leaflet is very limited to add the option in a PR for folium. (I guess that it is a css thing, right?)
This functionality would be useful, and adding it looks doable via Leaflet's onEachFeature: http://leafletjs.com/examples/geojson.html.
Create code and html as gists and add a README.md entry using http://bl.ocks.org for:
Location indicated by circle_marker seems to change as function of which location that map was initialized as.
For example, this location of
map_2.circle_marker(location=[45.5215, -122.6261], radius=500,
popup='Laurelhurst Park', line_color='#3186cc',
fill_color='#3186cc')
seems to be dependent on
map_2 = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',
zoom_start=13)
Is there a way to add custom HTML and JS to the output page? Something like following would be nice, for example
my_before = '<script> abc ... </script>'
my_after = '<p> Arctic Ocean</p>'
create_map('abc.html', plugin_data=True, before=my_before, after=my_after)
Currently Folium has the ability to create markers using simple shapes, e.g. generic Leaflet, Polygon, Circle markers.
One great aspect of these is the ability to easily bind Vincent visualisations to the map enabling greater detail at popup locations.
However, when working with a Chloropleth map the addition of these markers can obscure additional detail.
For example, a map similar to the one below could be significantly enhanced by binding Vincent visualisations to each particular location.
That is a user could click on a particular location and be given additional info (e.g. Time Series).
Ideally this could be accomplished by binding regions to keys in a similar way to the chloropleth creation.
Except instead of data what the developer is binding is popup vincent visualisations.
I'm not entirely sure on the best way to undertake this and I feel as though it may be beyond my ability.
However all that may be required is the creation of markers as described by geographical data.
Unrelated note: Folium and Vincent are both very cool!
Hi,
I've tried to install it on a fresh-new virtualenv using:
workon ENV
pip install folium
then trying to import folium via the python console: it gave me a
ImportError: No module named pandas
Manual installation of pandas didn't solve it, btw, since I was unable to compile numpy on my Macbook... :(
Is there a way of making use of the https://github.com/Leaflet/Leaflet.markercluster plugin and hence the L.markerClusterGroup layout from folium?
When both markers and geo_json methods are called, we cannot click in the markers in order to see their popup (at least on firefox).
It seems that it is because the html code to manage the geojson is called after the javascript code which manages the markers.
The issue appears even if the geo_json python method is called in first.
Manually modifing the html code in order to call L.geoJson before L.circle solves the issue
On my notebooks the first tile is always offset.
It seems there is a top margin for all but the first tile
because of the following css selector in style.css:
.rendered_html * + img
maybe adding some css to override margins is an good idea
How I should configure folium.Map
object if I want to get the following map option:
crs: L.CRS.Simple
Hi Wrobstory,
This is a fantastic library. While I like how you have made it very easy to make maps with tilesets, I would be interested in an option where you don't have a tileset at all but instead use GeoJSON/TopoJSON as the map. For my current use-case, I need only a simple US States maps with points and would like to have a very simple map. Rightnow I can use something like:
tileset = r'' geo_map = folium.Map(location=[35.1759, -112.6016], zoom_start=6, tiles=tileset,attr='My Data Attribution')
But it would be nice to be able to pass tileset=none
and use GeoJSON directly.
Along the lines of making simple maps, it would be nice to customize the width and height of the output map.
best regards,
zach cp
Its possible to use Folium to map using data and geometry from a GeoPandas object, but it requires writing the GeoPanda geometry to geojson (using the .to_json method);
something like, for gp being a geopandas obejct:
open("geom.json","w").write(gp.to_json())
and then you can map a column 'q' in the GeoPandas object:
map.geo_json("geom.json", data=gp, columns=["name", "q"], key_on='feature.properties.name', ...etc)
It should be possible to remove the steps of writing the json and the keying for a GeoPandas frame. Something like:
map_osm.geo_json(gp, column="q",....etc...)
addition of custom markers for ploting on the map, or an attribute to change the color or the marker when its created.
The colour mapping when generating choropleth style maps is based around d3.js colour brewer sequential scales.
When generating thematic maps based on a categorical variable (such as election prediction or outcomes by party), it would be convenient to be able to pass in a colour map as a dict that maps {'colvar1':color1, 'colvar2':color2, ..., 'colvarN':colorN}
One option would be to support colorbrewer qualitative scales, though it would also be useful to be able to define color maps for cases where conventional colorings are used (as for political parties, for example).
I can't offhand see how to do that currently?
I note that is a quantize_fill parameter in json_style
within the geo_json
function. Is that provided as a stub for such a feature?
If i do:
map.geo_json(geo_path=geo_json, data=series, key_on='feature.id')
I don't need to pass the columns argument, as it is a series. However, columns, initialized as None, is used in the function.
/home/gonzalo/anaconda/lib/python2.7/site-packages/folium/folium.pyc in geo_json(self, geo_path, geo_str, data_out, data, columns, key_on, threshold_scale, fill_color, fill_opacity, line_color, line_weight, line_opacity, legend_name, topojson, reset)
621
622 #D3 Color scale
--> 623 series = data[columns[1]]
624 domain = threshold_scale or utilities.split_six(series=series)
625 if len(domain) > 6:
TypeError: 'NoneType' object has no attribute '__getitem__'
Installing from git using Py 3.4:
pip3 install git+https://github.com/wrobstory/folium.git
and running in IPython notebook:
import folium
folium.initialize_notebook()
map = folium.Map(location=[40, -99], zoom_start=4)
map.simple_marker([40.67, -73.94], popup='Add <b>popup</b> text here.')
map
I get the following error:
---------------------------------------------------------------------------
TemplateNotFound Traceback (most recent call last)
<ipython-input-2-4f6f4e763ad5> in <module>()
----> 1 map = folium.Map(location=[40, -99], zoom_start=4)
2 map.simple_marker([40.67, -73.94], popup='Add <b>popup</b> text here.')
3 map
/usr/local/lib/python3.4/dist-packages/folium/folium.py in __init__(self, location, width, height, tiles, API_key, max_zoom, zoom_start, attr)
160 join_tile_path = functools.partial(os.path.join, 'tiles', tile)
161 self.tile_types[tile] = {
--> 162 'templ': self.env.get_template(join_tile_path('tiles.txt')),
163 'attr': self.env.get_template(join_tile_path('attr.txt')),
164 }
/usr/local/lib/python3.4/dist-packages/jinja2/environment.py in get_template(self, name, parent, globals)
789 if parent is not None:
790 name = self.join_path(name, parent)
--> 791 return self._load_template(name, self.make_globals(globals))
792
793 @internalcode
/usr/local/lib/python3.4/dist-packages/jinja2/environment.py in _load_template(self, name, globals)
763 template.is_up_to_date):
764 return template
--> 765 template = self.loader.load(self, name, globals)
766 if self.cache is not None:
767 self.cache[name] = template
/usr/local/lib/python3.4/dist-packages/jinja2/loaders.py in load(self, environment, name, globals)
111 # first we try to get the source for this template together
112 # with the filename and the uptodate function.
--> 113 source, filename, uptodate = self.get_source(environment, name)
114
115 # try to load the code from the bytecode cache if there is a
/usr/local/lib/python3.4/dist-packages/jinja2/loaders.py in get_source(self, environment, template)
223 p = '/'.join((self.package_path,) + tuple(pieces))
224 if not self.provider.has_resource(p):
--> 225 raise TemplateNotFound(template)
226
227 filename = uptodate = None
TemplateNotFound: tiles/openstreetmap/tiles.txt
Is there a way to add a url to the popup so that once the popup is clicked it redirects to the url?
at the min there is a dependency to the following link it should re removed, or moved to the folium project
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.