-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.py
More file actions
70 lines (53 loc) · 2.52 KB
/
configuration.py
File metadata and controls
70 lines (53 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Configure heppyplotlib or the underlying matplotlib."""
import matplotlib.pyplot as plt
def use_tex(use_serif=True, overwrite=True, preamble=None):
"""Configure pyplot to use LaTeX for text rendering."""
if plt.rcParams['text.usetex'] and not overwrite:
print("Will not override tex settings ...")
return
print("Will use tex for rendering ...")
if preamble is None:
if use_serif:
plt.rc('font', family='serif')
preamble = [r'\usepackage{amsmath}',
r'\usepackage{siunitx}',
r'\usepackage{hepnames}']
else:
# note that we do not even have a capital delta character (\Delta) apparently ...
# TODO: use a more complete sans serif font
preamble = [r'\usepackage{amsmath}',
r'\renewcommand*\familydefault{\sfdefault}',
r'\usepackage{siunitx}',
r'\usepackage{hepnames}',
r'\sisetup{number-mode=text}', # force siunitx to actually use your fonts
r'\usepackage{sansmath}', # load up the sansmath for sans-serif math
r'\sansmath'] # enable sansmath
plt.rcParams['text.latex.preamble'] = " ".join(preamble)
plt.rc('text', usetex=True)
def set_font_sizes(normal=9, small=8, large=10):
r"""Configure pyplot to use these two font sizes.
Match LaTeX paper font sizes using:
.. code-block:: latex
\makeatletter
\newcommand\thefontsize[1]{{#1 The current font size is: \f@size pt\par}}
\makeatother
e.g. extract the font sizes for captions and subcaptions (as in the example)
"""
params = {'font.size': normal, # \thefontsize\small (like captions)
'figure.titlesize': large,
'axes.titlesize': normal,
'axes.labelsize': normal,
'legend.fontsize': small,
'xtick.labelsize': small, # \thefontsize\footnotesize (like subcaptions)
'ytick.labelsize': small}
plt.rcParams.update(params)
def set_figure_size(latex_width, aspect_ratio=0.6875):
r"""Set figure size given a width in LaTeX points.
Match LaTeX paper text width using:
.. code-block:: latex
\the\textwidth
"""
tex_points_per_inch = 72.27
inches_per_tex_point = 1.0 / tex_points_per_inch
inches_width = latex_width * inches_per_tex_point
plt.rc('figure', figsize=[inches_width, inches_width * aspect_ratio])