geoplotlib
geoplotlib copied to clipboard
Jupyter integration
Hey Andrea,
Do you have any idea how to embed the pyglet window into a jupyter notebook? Currently I output as an image and just reference it from there. Any better idea or integration available?
Unfortunately you cannot embed a live pyglet canvas, but you can inline a screenshot using geoplotlib.inline()
in a cell within your notebook.
Good idea, thanks! I get that exception when doing it from my jupyter notebook:
C:\Anaconda3\lib\site-packages\geoplotlib\__init__.py in inline(width)
69 if os.path.isfile(fname + '.png'):
70 with open(fname + '.png', 'rb') as fin:
---> 71 base64 = urllib.parse.quote(fin.read().encode("base64"))
72
73 image_html = "<img style='width: %dpx; margin: 0px; float: left; border: 1px solid black;' src='data:image/png;base64,%s' />" % (width, base64)
AttributeError: 'bytes' object has no attribute 'encode'
Python 3.5.2 and geoplotlib (0.3.1) if that matters.
I think it is an issue with the encode
method which was discontinued in python 3.
I will try to take a look.
Related question - I am able to use geoplotlib.inline() successfully. However, if I export the notebook to pdf, the plots do not show. I am wondering if there is any solution to this.
Here is a fix for the error in python 3.5.2 and geoplotlib 0.3.2:
$ diff /usr/local/lib/python3.5/dist-packages/geoplotlib/__init__.py /usr/local/lib/python3.5/dist-packages/geoplotlib/__init__.py.bak
1d0
< import base64
72,75c71
< encoded = base64.b64encode(fin.read())
< b64 = urllib.parse.quote(encoded)
<
< image_html = "<img style='width: %dpx; margin: 0px; float: left; border: 1px solid black;' src='data:image/png;base64,%s' />" % (width, b64)
---
> base64 = urllib.parse.quote(fin.read().encode("base64"))
76a73,74
> image_html = "<img style='width: %dpx; margin: 0px; float: left; border: 1px solid black;' src='data:image/png;base64,%s' />" % (width, base64)
>
@kkaiser Could you PR those changes so we might get a working version for python3, please?
Done: https://github.com/andrea-cuttone/geoplotlib/pull/44