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

Skip to content

UnicodeEncodeError when trying to save a figure #4275

Closed
@Nodd

Description

@Nodd

Run the following code under python2, then try to save the figure but clicking on the floppy button :

import matplotlib.pyplot as plt
fig = plt.figure()
fig.canvas.set_window_title(u"unïcode")
plt.show()

The window for choosing a filename doesn't open and this traceback is printed:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 707, in save_figure
    start = os.path.join(startpath, self.canvas.get_default_filename())
  File "/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2254, in get_default_filename
    default_filename = self.get_window_title() or 'image'
  File "/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2239, in get_window_title
    return self.manager.get_window_title()
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 560, in get_window_title
    return str(self.window.windowTitle())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xef' in position 2: ordinal not in range(128)

It works fine on python3.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions