Skip to content

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte #11

Closed
@justineuro

Description

@justineuro

Bug summary

plt.scatter gives UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte error with notebook running python3 ipykernel, matplotlib-3.4.3, backend: module://matplotlib_inline.backend_inline.

Works fine when kernel is switched to python2, matplotlib-2.2.3, backend: module://ipykernel.pylab.backend_inline .

Code for reproduction

import matplotlib.pyplot as plt

X = [590,540,740,130,810,300,320,230,470,620,770,250]
Y = [32,36,39,52,61,72,77,75,68,57,48,48]
print(X)
print(Y)

plt.scatter(X,Y)

Actual outcome

[590, 540, 740, 130, 810, 300, 320, 230, 470, 620, 770, 250]
[32, 36, 39, 52, 61, 72, 77, 75, 68, 57, 48, 48]
<matplotlib.collections.PathCollection at 0x7fd16a4d8390>
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
~/.local/lib/python3.7/site-packages/matplotlib_inline/backend_inline.py in show(close, block)
     41             display(
     42                 figure_manager.canvas.figure,
---> 43                 metadata=_fetch_figure_metadata(figure_manager.canvas.figure)
     44             )
     45     finally:

~/.local/lib/python3.7/site-packages/IPython/core/display.py in display(include, exclude, metadata, transient, display_id, *objs, **kwargs)
    325                 # kwarg-specified metadata gets precedence
    326                 _merge(md_dict, metadata)
--> 327             publish_display_data(data=format_dict, metadata=md_dict, **kwargs)
    328     if display_id:
    329         return DisplayHandle(display_id)

~/.local/lib/python3.7/site-packages/IPython/core/display.py in publish_display_data(data, metadata, source, transient, **kwargs)
    120         data=data,
    121         metadata=metadata,
--> 122         **kwargs
    123     )
    124 

~/.local/lib/python3.7/site-packages/ipykernel/zmqshell.py in publish(self, data, metadata, transient, update)
    137 
    138         self.session.send(
--> 139             self.pub_socket, msg, ident=self.topic,
    140         )
    141 

~/.local/lib/python3.7/site-packages/jupyter_client/session.py in send(self, stream, msg_or_type, content, parent, ident, buffers, track, header, metadata)
    828         if self.adapt_version:
    829             msg = adapt(msg, self.adapt_version)
--> 830         to_send = self.serialize(msg, ident)
    831         to_send.extend(buffers)
    832         longest = max([len(s) for s in to_send])

~/.local/lib/python3.7/site-packages/jupyter_client/session.py in serialize(self, msg, ident)
    702             content = self.none
    703         elif isinstance(content, dict):
--> 704             content = self.pack(content)
    705         elif isinstance(content, bytes):
    706             # content is already packed, as in a relayed message

~/.local/lib/python3.7/site-packages/jupyter_client/session.py in json_packer(obj)
     97         default=json_default,
     98         ensure_ascii=False,
---> 99         allow_nan=False,
    100     )
    101 

/usr/lib/python3/dist-packages/zmq/utils/jsonapi.py in dumps(o, **kwargs)
     38         kwargs['separators'] = (',', ':')
     39 
---> 40     s = jsonmod.dumps(o, **kwargs)
     41 
     42     if isinstance(s, unicode):

/usr/lib/python3/dist-packages/simplejson/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, encoding, default, use_decimal, namedtuple_as_object, tuple_as_array, bigint_as_string, sort_keys, item_sort_key, for_json, ignore_nan, int_as_string_bitcount, iterable_as_array, **kw)
    397         ignore_nan=ignore_nan,
    398         int_as_string_bitcount=int_as_string_bitcount,
--> 399         **kw).encode(obj)
    400 
    401 

/usr/lib/python3/dist-packages/simplejson/encoder.py in encode(self, o)
    294         # exceptions aren't as detailed.  The list call should be roughly
    295         # equivalent to the PySequence_Fast that ''.join() would do.
--> 296         chunks = self.iterencode(o, _one_shot=True)
    297         if not isinstance(chunks, (list, tuple)):
    298             chunks = list(chunks)

/usr/lib/python3/dist-packages/simplejson/encoder.py in iterencode(self, o, _one_shot)
    376                 self.iterable_as_array, Decimal=decimal.Decimal)
    377         try:
--> 378             return _iterencode(o, 0)
    379         finally:
    380             key_memo.clear()

/usr/lib/python3/dist-packages/simplejson/encoder.py in encode_basestring(s, _PY3, _q)
     42     if _PY3:
     43         if isinstance(s, bytes):
---> 44             s = str(s, 'utf-8')
     45         elif type(s) is not str:
     46             # convert an str subclass instance to exact str

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

Expected outcome

plt.show() right after this should give an image of the plot.

Operating system

Debian 10 (Skolelinux)

Matplotlib Version

3.4.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.7.3

Jupyter version

5.7.8

Other libraries

No response

Installation

pip

Conda channel

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions