Skip to content
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

Jupyter integration #15

Open
thomasjungblut opened this issue Jul 26, 2016 · 7 comments
Open

Jupyter integration #15

thomasjungblut opened this issue Jul 26, 2016 · 7 comments

Comments

@thomasjungblut
Copy link

thomasjungblut commented Jul 26, 2016

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?

@andrea-cuttone
Copy link
Owner

Unfortunately you cannot embed a live pyglet canvas, but you can inline a screenshot using geoplotlib.inline() in a cell within your notebook.

@thomasjungblut
Copy link
Author

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.

@andrea-cuttone
Copy link
Owner

I think it is an issue with the encode method which was discontinued in python 3.

I will try to take a look.

@willjhenry
Copy link

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.

@kkaiser
Copy link
Contributor

kkaiser commented Feb 28, 2017

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)
>         

@timgrossmann
Copy link
Contributor

@kkaiser Could you PR those changes so we might get a working version for python3, please?

@kkaiser
Copy link
Contributor

kkaiser commented Nov 26, 2018

Done: #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants