[Matplotlib-users] latex with graphical backend and svg savefig

edgar at openmail.cc edgar at openmail.cc
Sun Nov 4 03:17:43 EST 2018


1. I want to report a possible issue (I don't want an account on 
GitHub... Micro$hit):

texmanager.py has

@ line 251:

         if rcParams['text.latex.unicode']:
             unicode_preamble = r"""
             unicode_preamble = ''

@ line 299:

             if rcParams['text.latex.unicode']:

Due to font conflicts in my system [1], I need
   \usepackage{lmodern} \usepackage[QX]{fontenc}
(I tried with DejaVu Sans, without success). Adding it to the  rcParams  
in the  text.latex.preamble  does not help, because inputenc clashes 
with that. In another computer, if I disable  text.latex.unicode , 
Matplotlib tries to use ASCII, which creates an error.

I suggest that the first conditional is removed (since  
text.latex.unicode  is depreceated anyway), but I don't know how the 
unicode characters are going to be handled once that depreciation 
happens (second conditional). Again, I didn't get that issue (ASCII) 
with Parabola.

2. I want a SVG and to be able to show the figure on screen (possibly 
save it from the new window). How can I achieve that?

This [2] didn't work.

     ! Font TS1/cmr/m/it/16=tcti1728 at 17.28pt not loadable: Metric 
(TFM) file not
     <to be read again>
     l.14 ...0000}{\rmfamily \textit{Velocity (°/sec)}

My failed attempt is below [3]

I tried to make this clear, but let me know if something needs 
clarification. Thanks!

My system:
Parabola GNU/Linux
pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
{'dirty': False, 'error': None, 'full-revisionid': 
'682e5195fae83393a75c71e84d1434cc9ff255fb', 'version': '3.0.1'}
(installed with pip)

[1] https://wiki.parabola.nu/TeXLive

import matplotlib as mpl
from matplotlib import pyplot as pl
# https://tex.stackexchange.com/a/391078
# https://3diagramsperpage.wordpress.com/category/matplotlib/
family = "DejaVu Sans"
serif, sans_serif, mono = [family] * 3
size = 14
labelsize = 12
legfontsize = 10
ticksize = 10
pgf_with_latex = {  # setup matplotlib to use latex for output
     "text.usetex": True,   # use LaTeX to write all text
     # "text.latex.unicode": True,        # 
     "font.family": family,
     "font.serif": serif,  # blank entries should cause plots
     "font.sans-serif": sans_serif,  # to inherit fonts from the document
     "font.monospace": mono,
     # LaTeX default is 10pt font.
     "axes.labelsize": labelsize,
     "font.size": size,
     "legend.fontsize": legfontsize,  # Make the legend/label fonts
     "xtick.labelsize": ticksize,     # a little smaller
     "ytick.labelsize": ticksize,
     "text.latex.preamble": [
         # plots will be generated using this preamble
         # r"\usepackage[utf8x]{inputenc}",  # use utf8 fonts
         r"\usepackage{lmodern} \usepackage[QX]{fontenc}",


pl.plot([1e-6, 2e-6], label=r"μ")


ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!  
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!  

More information about the Matplotlib-users mailing list