4

I am plotting data with matplotlib including LaTeX fonts. The pdf created can be displayed by evince, inkscape, GIMP but not by acroread resp. adobe reader. The code prototype works with a lot of figures and only a few plots have this problem.

...
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111)
savedpi = 250
fileformat = 'pdf'
... 
p12,=ax.plot(plimit12-binSize/2.0, mean12, '-', lw=2)
ax.set_yscale('log')
ax.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
ax.legend([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12], [ "C01", "C02", "C03",  "C04", "C05", "C06", "C07", "C08", "C09", "C10", "C11", "C12"],numpoints=1, loc=1, ncol=3) 
plt.savefig(savepath+'veloDisp'+'.pdf',dpi=None,format=fileformat)

One of these problematic files is to be fount at http://ubuntuone.com/0kuZIKYeZQyGckE5jonPy6

Did anyone encounter such a problem?

EDIT: Thank you William Denman, in fact opening in evince and printing into pdf works, it can be viewed in acroread as well now. Interestingly, other plots with LaTeX Fonts work from the get go. I do not get any error messages from which I could guess where the problem lies, this is why I asked here in the first place. For now your workaround is fine, thank you. However I would really like to know how this can be avoided generally. As these plots should be part of a publication, I have to think also about those people using Adobe pdf viewers.

EDIT: As suggested, I opened a thread on the MPL developers mailing list, see http://matplotlib.1069221.n5.nabble.com/PDF-not-readable-by-Adobe-PDF-readers-td42580.html

EDIT: Solved by matplotlib developers! The problem was the line

ax.axvline(x=1, c='#000000', lw='2', alpha=0.5) 

which contains a string as line width. Should be

ax.axvline(x=1, c='#000000', lw=2, alpha=0.5)

Unfortunately standard pdf backend does not warn about this (yet).

  • 1
    If you export the pdf from evince or inkscape to a pdf. Can the second pdf be viewed in adobe acrobat. Personally, I've had nothing but trouble with acrobat and Linux. Also, are you embedding latex inside the pdf? This might be causing problems for acrobat as well. When you say 'cannot be displayed by acroread', do you get an error? Anything on stderr? – William Denman Dec 01 '13 at 16:42
  • what version of mpl are you using? Can you reliably generate bad files (if so, can you put together a minimal example?)? This sounds like a bug that should be reported. – tacaswell Dec 01 '13 at 22:21
  • I am using 1.2.1 but I cannot reproduce the error when stripping down the plot routine. The problem only occurs with very large problems; in my case its 12 approx. 4GB hdf5 files which are processed. Also the output files are OK when there is not much computation inside the plot script; so if I load these files and just read out and plot a certain quantity, then the saved PDFs do not have a problem. However when I do some processing of the data, the PDF seems to be not conforming Adobe standard. – Giant Molecular Klaus Dec 02 '13 at 09:06
  • @Giant Molecuar Klaus: link to erro file is gone. Do you still have it? – ZF007 Nov 18 '17 at 10:47

1 Answers1

0

After chasing my own bug in matplotlib I figured out based on this post and the referral the OP makes at matplotlib site that chasing bugs in matplotlib can be done with cairo. pip install cairo. Then on top of all other MPL imports add:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import ...

import matplotlib
matplotlib.use("cairo")

from matplotlib.backends.backend_pdf import PdfPages
..etc.

otherwise the chase will fail because the backend is already set and loaded....

ZF007
  • 3,708
  • 8
  • 29
  • 48