Reputation: 11
I just started migrating from matlab/mathematica to python for technical computing. I have been learning how to use the matplotlib.pyplot package and was hoping someone could help me with fonts. I ultimately need to save graphical output as pdf or eps files that I can open in Adobe Illustrator. Initially, my pdf and eps output contained outlined fonts (rather than embedded fonts retaining text information). Following this helpful advice, I ended up with the following code:
import matplotlib as mpl
import matplotlib.pyplot as plt
# if I omit the next line, the plot saves without error, but with outlined fonts
mpl.rcParams['pdf.fonttype'] = 42 #set Truetype fonts for Adobe
plt.plot(range(5),range(5),'r-')
plt.ylabel('y')
plt.xlabel('x')
plt.title('title')
plt.show()
plt.savefig("myfig.pdf")
However, when I set rcParams['pdf.fonttype']=42, the final line generates the error copied below. Can anyone point me in the right direction? I am running Python 3.3 and matplotlib 1.2.0, using the Pyzo distribution on Mac OS 10.6.
Traceback (most recent call last):
File "<tmp 1>", line 11, in <module> plt.savefig("myfig.pdf")
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/pyplot.py", line 472, in savefig
return fig.savefig(*args, **kwargs)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/figure.py", line 1364, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_qt4agg.py", line 161, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backend_bases.py", line 2093, in print_figure
**kwargs)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backend_bases.py", line 1845, in print_pdf
return pdf.print_pdf(*args, **kwargs)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 2307, in print_pdf
file.close()
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 507, in close
self.writeFonts()
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 607, in writeFonts
fonts[Fx] = self.embedTTF(realpath, chars[1])
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 1054, in embedTTF
return embedTTFType42(font, characters, descriptor)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 987, in embedTTFType42
self.currentstream.write(unicode_cmap)
File "/Applications/pyzo2013b/lib/python3.3/pyzo-packages/matplotlib/backends/backend_pdf.py", line 379, in write
compressed = self.compressobj.compress(data)
TypeError: 'str' does not support the buffer interface
Upvotes: 1
Views: 576
Reputation: 87526
This is a bug in matplotlib
and is fixed here: https://github.com/matplotlib/matplotlib/pull/1978#issuecomment-17493157
Upvotes: 1