Created
October 11, 2017 04:30
-
-
Save MatthewJA/6bcc68d95a06dce83d65ff1c932a60e8 to your computer and use it in GitHub Desktop.
Fix for Matplotlib text output for inclusion in LaTeX documents
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
import matplotlib | |
# http://bkanuka.com/articles/native-latex-plots/ | |
def figsize(scale): | |
fig_width_pt = 240.0 | |
inches_per_pt = 1.0/72.27 | |
golden_mean = (numpy.sqrt(5.0)-1.0)/2.0 | |
fig_width = fig_width_pt*inches_per_pt*scale | |
fig_height = fig_width*golden_mean | |
fig_size = [fig_width,fig_height] | |
return fig_size | |
pgf_with_latex = { | |
"pgf.texsystem": "pdflatex", | |
"text.usetex": True, | |
"font.family": "serif", | |
"font.serif": [], | |
"font.sans-serif": [], | |
"font.monospace": [], | |
"axes.labelsize": 12, | |
"font.size": 12, | |
"legend.fontsize": 12, | |
"xtick.labelsize": 12, | |
"ytick.labelsize": 12, | |
"figure.figsize": figsize(0.9), | |
"pgf.preamble": [ | |
r"\usepackage[utf8x]{inputenc}", | |
r"\usepackage[T1]{fontenc}", | |
] | |
} | |
matplotlib.rcParams.update(pgf_with_latex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment