Skip to content
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

matplotlib pdf backend, usetex and Times font doesn't work #337

Closed
joergdietrich opened this issue May 23, 2015 · 9 comments
Closed

matplotlib pdf backend, usetex and Times font doesn't work #337

joergdietrich opened this issue May 23, 2015 · 9 comments
Assignees
Labels

Comments

@joergdietrich
Copy link

The following example

import numpy as np
import matplotlib as mpl
import matplotlib.pylab as plt

mpl.rcdefaults()
# This doesn't work
mpl.rcParams['font.serif'] = "Times, serif"
# This does
# mpl.rcParams['font.serif'] = "Bitstream Vera Serif, serif"
mpl.rcParams['text.usetex'] = "true"

x = np.random.normal(size=100)
y = np.random.normal(size=100)
plt.scatter(x, y)
plt.xlabel("$\gamma$")
plt.savefig("foo.png")
print("foo.png saved")
plt.savefig("bar.pdf")
print("bar.pdf saved")

produces

$ python latex_plots.py 
foo.png saved
Traceback (most recent call last):
  File "latex_plots.py", line 20, in <module>
    plt.savefig("bar.pdf")
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/pyplot.py", line 577, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/figure.py", line 1476, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2211, in print_figure
    **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/backends/backend_pdf.py", line 2491, in print_pdf
    file.close()
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/backends/backend_pdf.py", line 525, in close
    self.writeFonts()
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/backends/backend_pdf.py", line 621, in writeFonts
    self.dviFontInfo[filename])
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/backends/backend_pdf.py", line 686, in embedTeXFont
    t1font = t1font.transform(fontinfo.effects)
  File "/home/joerg/applications/anaconda3/lib/python3.4/site-packages/matplotlib/type1font.py", line 336, in transform
    value = value.encode('latin-1')
AttributeError: 'bytes' object has no attribute 'encode'

Note that text.usetex needs to be true, a LaTeX symbol like \gamma has to be used, the font needs to be Times, and the backend pdf for this example to fail.

@joergdietrich
Copy link
Author

This is with
matplotlib 1.4.3 np19py34_1

@ccordoba12
Copy link

This seems to be a bug in Matplotlib.

@tacaswell, is this problem known to you?

@ccordoba12 ccordoba12 self-assigned this May 25, 2015
@tacaswell
Copy link

Does indeed look like a mpl bug and I do not recognize this off the top of my head.

@tacaswell
Copy link

@ccordoba12 This issue can be closed as fix required upstream.

@ccordoba12
Copy link

Great!! Thanks for the prompt answer :-)

@rajaditya-m
Copy link

Hi is this issue fixed? I updates Anaconda right now and I am still getting this issue.

@tacaswell
Copy link

Should have been fixed by matplotlib/matplotlib#4522 which should be included in mpl 1.5

@rajaditya-m
Copy link

HI Thomas,

I just updated Matplotlib explicitly using conda update and the issue is still persisting. Will it be in the next release?

@tacaswell
Copy link

I can not reproduce this with mpl 1.5.1 + python 3.5. You may have found a new bug or are not running in the enviroment you think you are using.

Can you please provide (in a new issue) a minimal script to reproduce along with the trace back you are seeing, mpl version, python version, and OS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants