Created
December 10, 2018 14:21
-
-
Save avonmoll/e0e7939e9a71865050f3beb22cc40ca6 to your computer and use it in GitHub Desktop.
Startup file for IPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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