jwass / mplleaflet

Easily convert matplotlib plots from Python into interactive Leaflet web maps.
BSD 3-Clause "New" or "Revised" License
521 stars 76 forks source link

display() doesn't work - 'base64' is not a text encoding #29

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi. I've recently downloaded the package and have been messing around with some basic examples.

The following snippet runs without error,

%matplotlib inline

import mplleaflet
import matplotlib.pyplot as plt

plt.plot([0,45], [0,45])

mplleaflet.show()

but changing mplleaflet.show() to mplleaflet.display() returns the following error

---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
<ipython-input-6-a8022d0ab3fb> in <module>()
      6 plt.plot([0,45], [0,45])
      7 
----> 8 mplleaflet.display()

C:\Program Files\Miniconda3\lib\site-packages\mplleaflet\_display.py in display(fig, closefig, **kwargs)
    153     # We embed everything in an iframe.
    154     iframe_html = '<iframe src="data:text/html;base64,{html}" width="{width}" height="{height}"></iframe>'\
--> 155     .format(html = html.encode('base64'),
    156             width = '100%',
    157             height= int(60.*fig.get_figheight()),

LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs

I'm running Python 3.4.3, iPython 4.0.0 through Jupyter 4.0.6, matplotlib 1.4.3 and mplleaflet 0.0.4. OS is Win8.1 (64bit).

Cheers, Eilam

BibMartin commented 9 years ago

My fault ; I wrote this line of code with python 2.7 and did not test with python 3.

I fix this in PR #30

jwass commented 9 years ago

Fixed in 4b945fd0c20e65e662900728551e20006d5ad92f

aflyax commented 8 years ago

Still getting the same error for display():

---------------------------------------------------------------------------
LookupError                               Traceback (most recent call last)
<ipython-input-32-4805ed8aa6a4> in <module>()
----> 1 mplleaflet.display()

/home/aflyax/anaconda3/lib/python3.5/site-packages/mplleaflet/_display.py in display(fig, closefig, **kwargs)
    153     # We embed everything in an iframe.
    154     iframe_html = '<iframe src="data:text/html;base64,{html}" width="{width}" height="{height}"></iframe>'\
--> 155     .format(html = html.encode('base64'),
    156             width = '100%',
    157             height= int(60.*fig.get_figheight()),

LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs
BibMartin commented 8 years ago

@aflyax Are you sure you're using the master version ? You code line 155 seems to be different than 4b945fd's code...

jwass commented 8 years ago

Hi @eilamgbrz - I just uploaded to PyPI the latest version containing the fix for this issue. You can either use master on the repo or upgrade to the latest version.

Can you give that a try and let us know if that fixes it?

Thanks for taking a look too, @BibMartin

ghost commented 8 years ago

Works fine for me.