pbugnion / gmaps Goto Github PK
View Code? Open in Web Editor NEWGoogle maps for Jupyter notebooks
Home Page: https://jupyter-gmaps.readthedocs.io/en/stable/
License: Other
Google maps for Jupyter notebooks
Home Page: https://jupyter-gmaps.readthedocs.io/en/stable/
License: Other
Fix installation instructions to mention pip install.
I have tried running the simple example:
import gmaps
import gmaps.datasets
gmaps.configure(api_key="AIzaSyDOESksOPLhqEw...")
m = gmaps.Map()
m
but nothing shows up - the kernel keeps running forever. In the terminal it says:
(404 GET /static/jupyter-gmaps.js?v=20160823123004 (127.0.0.1) 9.95ms referer=http://localhost:8888/notebooks/test-gmaps.ipynb)
(from #60)
Some room for improvements, here are some reflections:
import googlemaps
import gmaps
client = googlemaps.Client(">>>> fill in your API key <<<<")
location = client.geocode("Toulouse")
print (location) # have a look!
gmaps.add_layer(Directions(data=[client.geocode("Toulouse"), client.geocode("Paris")]))
data
). More generally, it would be great to have a close interface to googlemaps
and write:# from googlemaps documentation
directions_result = client.directions("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now)
# how about this ?
gmaps.add_layer(Directions("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now))
For future references, there is a good overview of the interface here.
The earthquake dataset is a list of triples, so it breaks when passing it to the HeatMap.
Google JS API allows weighted heatmap. We need this.
I am trying to install gmaps using pip on ubuntu 14.04
However I am getting the following issue
Collecting gmaps
Downloading gmaps-0.1.6.tar.gz (98kB)
100% |████████████████████████████████| 102kB 75kB/s
Complete output from command python setup.py egg_info:
/usr/local/lib/python2.7/dist-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
"`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
/usr/local/lib/python2.7/dist-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-3069XK/gmaps/setup.py", line 7, in <module>
import gmaps
File "gmaps/__init__.py", line 3, in <module>
from heatmap import heatmap
File "gmaps/heatmap.py", line 8, in <module>
class HeatmapWidget(widgets.DOMWidget):
File "/usr/local/lib/python2.7/dist-packages/IPython/utils/shimmodule.py", line 92, in __getattr__
raise AttributeError(key)
AttributeError: DOMWidget
Heatmap was developed on IPython v3.0. It needs to work on v2.3.
It would be good to be able to set the centre and zoom on maps (cf issue #80). An interface like:
m = Map(zoom=8, centre=[-5.0, 5.0], centre_on_data=False)
would work. The centre_on_data
argument is useful to stop the default behaviour which recanters the map so it always bounds the data.
It would be nice to be able to unittest the widgets themselves. Maybe phantom.js
? This seems to be what the IPython notebook uses to test the widgets.
Running the following code does not produce any output on Ipython Notebook v3.2.0 and Python 2.7.10
import gmaps
data = [ [ 37.782551,-122.445368 ],
[ 37.782745,-122.444586 ],
[ 37.782842,-122.443858 ] ]
gmaps.heatmap(data)
No Warnings (except for
:0: FutureWarning: IPython widgets are experimental and may change in the future
.) and No Errors.
This package is missing a requirements.txt file. It's not a big deal, since the packages required are pretty obvious (IPython, Numpy), but we should still have one.
There are two problems with the installation / initialisation of gmaps, AFAICT:
Hey everyone,
I was wondering what the best way would be to go about changing the heatmap properties.
I tried using the google heatmap reference but didn't get very far.
I am sorry if this is a dumb question, I'm not very experienced.
Thanks in advance!
Heatmap really needs an example notebook as a very basic form of documentation.
This package desperately needs documentation. Unfortunately, the obvious solution of writing IPython notebooks and exporting them to HTML doesn't work. Javascript widgets are not included in the exported HTML, so you can't actually see the maps (see this, for instance).
I think that the solution will be to write a custom 'nbexport' script, but that sounds like a real pain.
When enabling widget extension for Jupyter I get:
[EnableNBExtensionApp] CRITICAL | Bad config encountered during initialization: [EnableNBExtensionApp] CRITICAL | Unrecognized flag: '--py'
I tried to look around on Jupyter shell commands but couldn't find reference to '--py' on help pages
Am I missing some package etc?
Heatmap dissipates when you zoom in too closely.
I like the scikit-learn datasets module. It would be nice to have something like
np_array = gmaps.datasets.taxi_data.load_dataset()
We do bundle data in in the examples at the moment, but it's a pain for the user to have to search for the file in the appropriate site-packages directory.
C:\Users\XXX\AppData\Local\Continuum\Anaconda3>pip install gmaps
Collecting gmaps
Downloading gmaps-0.1.6.tar.gz (98kB)
100% |################################| 102kB 1.5MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 20, in
File "C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps\setup.py", line 7, in
import gmaps
File "C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps\gmaps__init__.py", line 2, in
from loader import init
ImportError: No module named 'loader'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\XXX\AppData\Local\Temp\pip-build-m3s6zj_3\gmaps
The data array passed to Heatmap
and Directions
has to be a list of lists at the moment. This goes against the expectation that duck-typing works in Python. For instance, the following should just work for any pandas data frame df
:
Heatmap(data=df[["latitude", "longitude"]])
The reason this is currently broken is that data
is a traitlet. Changing this to a private variable that we fill in by iterating over what the user passes would be better.
This is missing a tutorial. The docstring also needs to be integrated into the API documentation.
Do you plan to support a more open solution like leaflet or openlayers or do you know alternatives?
What I found was only this project: https://github.com/SciTools/cartopy
Edit: found one: https://github.com/python-visualization/folium
It would probably be a nice thing to have something like:
import gmaps
m = gmaps.Map()
m.add_layer(...)
m.save("map.png")
Google Static Maps API
may help? It would be nice to investigate.
When I try to type import gmaps into the terminal it gives me the following error:
----> 2 from IPython.html import widgets
3 from IPython.utils.traitlets import List, Unicode, Bool
4
5 import ipy23_compat
ImportError: cannot import name widgets
I'm using python 64 bit 2.7 on canopy gmaps version 0.1.6 and python version 2.4.1
I am getting the following error in browser console when trying the example on README.rst
, what could be the most likely cause, please?
WrappedError {stack: "Error: Couldn't create a view for model id '098ff7…s-widgets/extension.js?v=20160512124824:32043:30)", message: "Couldn't create a view for model id '098ff76350694707a8ed2de25b6b3eac'", error_stack: Array[2]}
error_stack: Array[4]
0: Error: Class HeatmapView not found in registry at http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32009:25 at Object.loadClass (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31970:13) at http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32193:23
1: Error: Couldn't create a view for model id '098ff76350694707a8ed2de25b6b3eac' at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
2: Error: Could not create view at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
3: Error: Could not display model at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
4: Error: Could not get state of widget manager at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
5: Error: Could not call widget save state callback. at new Error (native) at Error.WrappedError (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:31936:22) at promiseRejection (http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20160512124824:32043:30)
message: "Could not call widget save state callback."
...
It would be good to give access to the following options:
See, eg. issue #73 .
Options like "width", "height", "bounds" and "center", at least.
Attempts to set "dissipating : false" leads to bugs. This is strange, since leaving it undefined (which is what we do at the moment) should, as per the JavaScript API docs, amount to setting it to false.
This is a continuation of #27.
The homepage and license information should be passed as argument to setup.
Should also include links to those in long_description.
gmap notebook.ipynb.zip
Hello
I have attached the ipynb file that I used while working on this problem. I removed the API key.
goal: load simple local csv files directly.
I have tried many options(see below). What code would you recommend I use to get a local csv to load properly?
thank you
Dennis
import numpy as np
import gmaps
gmaps.configure(api_key="AIyourAPIKeyGoesHere")
m = gmaps.Map()
data = np.loadtxt("/home/dgd/Desktop/text.csv")
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m
error
import numpy as np
import gmaps
gmaps.configure(api_key="AIyourAPIKeyGoesHere")
m = gmaps.Map()
data = np.loadtxt("/home/dgd/Desktop/text.csv")
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m
error:
import numpy as np
import gmaps
gmaps.configure(api_key="AIyourAPIKeyGoesHere")
m = gmaps.Map()
data = np.genfromtxt("/home/dgd/Desktop/text.csv", delimiter=',')
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m
error:
TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'numpy.ndarray' (i.e. array([[ nan, nan],
[ 38., 0.],
[ 45., 0.]])) was specified.
import csv
import gmaps
gmaps.configure(api_key="AIyourAPIKeyGoesHere")
m = gmaps.Map()
with open('/home/dgd/Desktop/text.csv', 'rb') as f:
reader = csv.reader(f)
data =your_list = map(tuple, reader)
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m
error:
TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'map' (i.e. <map object at 0x7fa4ac122320>) was specified.
Hi,
first of all great lib.
is gmaps able to handle 200k geo points (lat/long)? How can you update the heatmap on the fly and add new datapoints?
Thanks
m.add_layer(gmaps.Heatmap(data=data))
yields
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
----> 1 m.add_layer(gmaps.Heatmap(data=data))
gmaps/maps.py in add_layer(self, layer)
62
63 def add_layer(self, layer):
---> 64 self.layers = tuple([l for l in self.layers] + [layer])
65
66 @default("layout")
traitlets/traitlets.py in __set__(self, obj, value)
556 raise TraitError('The "%s" trait is read-only.' % self.name)
557 else:
--> 558 self.set(obj, value)
559
560 def _validate(self, obj, value):
traitlets/traitlets.py in set(self, obj, value)
545 # we explicitly compare silent to True just in case the equality
546 # comparison above returns something other than True/False
--> 547 obj._notify_trait(self.name, old_value, new_value)
548
549 def __set__(self, obj, value):
traitlets/traitlets.py in _notify_trait(self, name, old_value, new_value)
1091 'new': new_value,
1092 'owner': self,
-> 1093 'type': 'change',
1094 })
1095
ipywidgets/widgets/widget.py in notify_change(self, change)
366 # Send new state to front-end
367 self.send_state(key=name)
--> 368 LoggingConfigurable.notify_change(self, change)
369
370 #-------------------------------------------------------------------------
traitlets/traitlets.py in notify_change(self, change)
1125 c = getattr(self, c.name)
1126
-> 1127 c(change)
1128
1129 def _add_notifiers(self, handler, name, type):
gmaps/maps.py in _calc_bounds(self, change)
71 def _calc_bounds(self, change):
72 layers = change["new"]
---> 73 bounds_list = [layer.data_bounds for layer in layers if layer.has_bounds]
74 if bounds_list:
75 min_latitude = min(bounds[0][0] for bounds in bounds_list)
gmaps/maps.py in <listcomp>(.0)
71 def _calc_bounds(self, change):
72 layers = change["new"]
---> 73 bounds_list = [layer.data_bounds for layer in layers if layer.has_bounds]
74 if bounds_list:
75 min_latitude = min(bounds[0][0] for bounds in bounds_list)
AttributeError: 'list' object has no attribute 'has_bounds'
Add Pypi categories to the setup script.
Here is info about my python:
(dato-env)dan@nia111:~/pg/dan $ python
Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>>
(dato-env)dan@nia111:~/pg/dan $ jupyter --version
4.1.0
(dato-env)dan@nia111:~/pg/dan $
I did
pip install gmaps
pip install ipywidgets
jupyter notebook
I see this:
import gmaps
data = gmaps.datasets.load_dataset('taxi_rides')
IOError: [Errno 2] No such file or directory: '/home/dan/anaconda3/envs/dato-env/lib/python2.7/site-packages/gmaps/datasets/metadata.json'
I am disappointed that it failed so early in the demo.
At the moment, this only accepts a list. It would be good if it also accepted Numpy arrays and dataframes.
At the moment, if the user feeds in non-numeric input as the argument data
to heatmap
, it is passed to the JavaScript which then fails silently. It would be better to raise an error.
It would be useful to be able to export a map to a static HTML / JS file. I think we could do this by:
This is somewhat related to issue #62 (saving maps as images).
The documentation doesn't show a basic example for this?
We only really want to version control the inputs.
At the moment, the map bounds are not re-calculated when the height of the widget is changed. I think a redraw of the map should be forced.
It would be wonderful to be able to save the displayed map as an image (png or whatever). Is it already feasible with the current version? If not do you think it can be added?
Everyone loves jQuery.
I have a list of 200,000 lat,lon pairs. The heatmap works fine until 1500 points. When set to 2000, it just show a regular map without heat. Is that there's a limit on how many points can be supported?
The code is running on jupyter in datascientist workbench with spark
import gmaps
longitude_list = sqlContext.sql("SELECT lon From table_15_1")
latitude_list = sqlContext.sql("SELECT lat From table_15_1")
data = []
for lat,lon in zip(latitude_list.collect()[:2000], longitude_list.collect()[:2000]):
point = []
point.append(lat)
point.append(lon)
data.append(point)
gmaps.heatmap(data)
When I export an ipython notebook as HTML, the map doesn't display. I'm wondering if there's any simple workaround for this.
Maybe either use the "require.js" format to import google, or a matplotlib style "%matplotlib inline" cell magic.
At the moment, layers accept a data array that is a list of (latitude, longitude) pairs. An alternative interface would be to have a pair of latitude, longitude arrays.
The motivation for passing in two arrays, one with latitude and one with longitude values, is that most modellers, data scientists etc. are used to dealing with tabular data, e.g. through a pandas dataframe. They might have a column of latitudes and a column of longitudes in their data frame.
Given that this is a major breaking change in the API if implemented, it's important to resolve this as early as possible.
This project is really visual. It would therefore benefit from having a decent website.
Maybe use Github pages as a stopgap?
This is related to #22.
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.