-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
71 lines (58 loc) · 2.13 KB
/
Copy pathutils.py
File metadata and controls
71 lines (58 loc) · 2.13 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
import os
import numpy as np
import matplotlib as mlt
import matplotlib.pyplot as plt
def checkFolder(folder):
"""
Check whether folder is present and creates them if necessary
"""
if not os.path.exists(folder):
print(f'Making directory {folder}')
os.makedirs(folder)
def axisEqual3D(ax):
'''
Set equal limits to the axis of a 3D matplotlib plot
https://stackoverflow.com/questions/8130823/set-matplotlib-3d-plot-aspect-ratio
'''
extents = np.array([getattr(ax, 'get_{}lim'.format(dim))() for dim in 'xyz'])
sz = extents[:,1] - extents[:,0]
centers = np.mean(extents, axis=1)
maxsize = max(abs(sz))
r = maxsize/2
for ctr, dim in zip(centers, 'xyz'):
getattr(ax, 'set_{}lim'.format(dim))(ctr - r, ctr + r)
def newFigure(height=4, half=False, target='thesis', dpi=300):
'''
Create a new figure, used to keep figure and font sizes consistent
Figures need to be saved with dpi=300
Calling plt.tight_layout() before saving is advised
'''
# matplotlib settings
# mlt.rcParams['font.family'] = ['serif']
# mlt.rcParams['font.serif'] = ['Times New Roman']
plt.rc('font', family='Times New Roman')
if target == 'thesis':
SMALL_SIZE = 7
MEDIUM_SIZE = 8
BIGGER_SIZE = 8
elif target == 'paper':
SMALL_SIZE = 7
MEDIUM_SIZE = 8
BIGGER_SIZE = 8
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
if target == 'thesis':
width = 6.2
elif target == 'paper':
width = 6.5
else:
print('ERRRRRRRoRRrr')
if half == True:
width = width/2
fig = plt.figure(figsize=(width, height), dpi=dpi)
return fig