Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG : nbagg py3k compatibility #3464

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

Merged
merged 3 commits into from
Sep 18, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
BUG : fix encoding of png data
When formatting the png data to send over the wire need to decode the
byte string to ascii.  If this is not done the literal string sent
to the browser is:
   "data:image/png;base64,b'iVBOR...'"
instead of
   "data:image/png;base64,iVBOR..."

The extra b' makes the string no longer a valid png which is why
we were getting white boxes
  • Loading branch information
tacaswell committed Sep 6, 2014
commit 3a9757cf2c79d28298b5901ed01e00fe4448f997
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import io
import os
import six
from uuid import uuid4 as uuid

from IPython.display import display, Javascript, HTML
Expand Down Expand Up @@ -193,7 +194,10 @@ def send_json(self, content):
def send_binary(self, blob):
# The comm is ascii, so we always send the image in base64
# encoded data URL form.
data_uri = "data:image/png;base64,{0}".format(b64encode(blob))
data = b64encode(blob)
if six.PY3:
data = data.decode('ascii')
data_uri = "data:image/png;base64,{0}".format(data)
self.comm.send({'data': data_uri})

def on_message(self, message):
Expand Down