3

when I run a modified version of Matplotlib's multi page example with a tab added to the title, I get the following output:

enter image description here

This is my working example. The comments above the code are suggestions I found here and in Non-ASCII characters in Matplotlib, but no success so far.

# -*- coding: utf-8 -*-
import matplotlib
from matplotlib.backends.backend_pdf import PdfPages
from pylab import *

#matplotlib.rc('font', family='DejaVu Sans')

#matplotlib.rc('font', **{'sans-serif' : 'Arial',
#                           'family' : 'sans-serif'})

#matplotlib.rcParams['pdf.fonttype'] = 42
#matplotlib.rcParams['ps.fonttype'] = 42

pdf = PdfPages('multipage_pdf.pdf')

figure(figsize=(3,3))
plot(range(7), [3,1,4,1,5,9,2], 'r-o')
title('Page\tOne')
savefig(pdf, format='pdf') # note the format='pdf' argument!
close()

pdf.close()

Any ideas how this could be solved?

Joe
  • 6,758
  • 2
  • 26
  • 47

1 Answers1

2

The solution is to add

matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
matplotlib.rcParams['text.usetex'] = True

as mentioned here and here.

I couldn't find out which line does the magic, not all seemed to be needed in my case, but I just added all. If there is a problem with tex complaining about not being able to encode something, you might be able to comment the ['text.usetex'] with it still working.

From the matplotlib doc:

Add "pdf.use14corefonts: True" in your configuration file to use only the 14 PDF core fonts. These fonts do not need to be embedded; every PDF viewing application is required to have them. This results in very light PDF files you can use directly in LaTeX or ConTeXt documents generated with pdfTeX, without any conversion.

These fonts are: Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Symbol, ZapfDingbats.

Joe
  • 6,758
  • 2
  • 26
  • 47