Closed
Description
Bug report
Bug summary
I use Python 3 and save data to files with Unicode names. Then I want to save figures with the same names.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 5)
y = np.sin(x)
fig = plt.figure()
plt.plot(x,y)
name = 'ωω'
plt.savefig(name + '.eps', format='eps', bbox_inches='tight')
Actual outcome
Traceback (most recent call last):
File "/opt/pycharm-professional/helpers/pydev/pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/opt/pycharm-professional/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/nik/.PyCharm2018.1/config/scratches/scratch.py", line 10, in <module>
plt.savefig(name + '.eps', format='eps', bbox_inches='tight')
File "/usr/lib/python3.6/site-packages/matplotlib/pyplot.py", line 710, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/figure.py", line 2035, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 94, in print_figure
super(FigureCanvasQTAgg, self).print_figure(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2263, in print_figure
**kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_ps.py", line 931, in print_eps
return self._print_ps(outfile, 'eps', *args, **kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_ps.py", line 959, in _print_ps
**kwargs)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_ps.py", line 1199, in _print_figure
print_figure_impl(fh)
File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_ps.py", line 1075, in print_figure_impl
print("%%Title: "+title, file=fh)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 9-10: ordinal not in range(256)
Expected outcome
A figure with given Unicode name
Matplotlib version
- Operating system: Linux thebox 4.16.3-1-ARCH
- Matplotlib version: 2.2.2
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.6.5