Skip to content

Instantly share code, notes, and snippets.

@avonmoll
Created December 10, 2018 14:21
Show Gist options
  • Save avonmoll/e0e7939e9a71865050f3beb22cc40ca6 to your computer and use it in GitHub Desktop.
Save avonmoll/e0e7939e9a71865050f3beb22cc40ca6 to your computer and use it in GitHub Desktop.
Startup file for IPython
# The main purpose of this file is to force matplotlib to use XeLaTeX with the fonts specified. Matplotlib's default
# font handling for PDF is really bad on macOS and the file sizes end up being massive
import numpy as np
import matplotlib as mpl
import importlib
from matplotlib.backends.backend_pgf import FigureCanvasPgf # For PGF or PDF export (uses TeX to render everything, no Type 3 fonts)
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf) #
pgf_with_rc_fonts = { # Comment these lines in order to go back to matplotlib's mathtex (Type 3 or Type 42 fonts)
"font.family": "sans-serif", #
"font.serif": ["TeX Gyre Pagella"], #
"font.sans-serif": ["TeX Gyre Heros"], #
"pgf.preamble": [
"\\usepackage{unicode-math}",
r"\setmathfont{TeX Gyre Pagella Math}"
]
} #
mpl.rcParams.update(pgf_with_rc_fonts) #
import matplotlib.pyplot as plt
plt.style.use('ggplot')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment