-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
90 lines (75 loc) · 3.12 KB
/
utils.py
File metadata and controls
90 lines (75 loc) · 3.12 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
def get_fig_dim(width, fraction=1):
"""Set figure dimensions to avoid scaling in LaTeX.
Parameters
----------
width: float
Document textwidth or columnwidth in pts
fraction: float, optional
Fraction of the width which you wish the figure to occupy
Returns
-------
fig_dim: tuple
Dimensions of figure in inches
"""
# Width of figure (in pts)
fig_width_pt = width * fraction
# Convert from pt to inches
inches_per_pt = 1 / 72.27
# Golden ratio to set aesthetic figure height
golden_ratio = (1 + 5**.5) / 2
# Figure width in inches
fig_width_in = fig_width_pt * inches_per_pt
# Figure height in inches
fig_height_in = fig_width_in / golden_ratio
fig_dim = (fig_height_in, golden_ratio)
return fig_dim
def latexify(font_serif='Computer Modern', mathtext_font='cm', font_size=10, small_font_size=None, usetex=True):
"""Set up matplotlib's RC params for LaTeX plotting.
Call this before plotting a figure.
Parameters
----------
fig_width : float, optional, inches
fig_height : float, optional, inches
columns : {1, 2}
"""
# code adapted from http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples
if small_font_size is None:
small_font_size = font_size
params = {'backend': 'ps',
'text.latex.preamble': '\\usepackage{gensymb} \\usepackage{bm}',
# fontsize for x and y labels (was 10)
# 'axes.labelsize': font_scale * 10 if largeFonts else font_scale * 7,
# 'axes.titlesize': font_scale * 10 if largeFonts else font_scale * 7,
# 'font.size': font_scale * 10 if largeFonts else font_scale * 7, # was 10
# 'legend.fontsize': font_scale * 10 if largeFonts else font_scale * 7, # was 10
# 'xtick.labelsize': font_scale * 10 if largeFonts else font_scale * 7,
# 'ytick.labelsize': font_scale * 10 if largeFonts else font_scale * 7,
'axes.labelsize': font_size,
'axes.titlesize': font_size,
'font.size': font_size, # was 10
'legend.fontsize': small_font_size, # was 10
'legend.title_fontsize': small_font_size,
'xtick.labelsize': small_font_size,
'ytick.labelsize': small_font_size,
'text.usetex': usetex,
# 'figure.figsize': [fig_width, fig_height],
'font.family' : 'serif',
'font.serif' : font_serif,
'mathtext.fontset' : mathtext_font
# 'xtick.minor.size': 0.5,
# 'xtick.major.pad': 1.5,
# 'xtick.major.size': 1,
# 'ytick.minor.size': 0.5,
# 'ytick.major.pad': 1.5,
# 'ytick.major.size': 1,
# # 'lines.linewidth': 1.5,
# 'lines.linewidth': 1,
# # 'lines.markersize': 0.1,
# 'lines.markersize': 8.0,
# 'hatch.linewidth': 0.5
}
matplotlib.rcParams.update(params)
plt.rcParams.update(params)