-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmydefaults.py
More file actions
75 lines (60 loc) · 2.36 KB
/
Copy pathmydefaults.py
File metadata and controls
75 lines (60 loc) · 2.36 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
import matplotlib as mpl
import matplotlib.font_manager
import numpy
def mydefaults(fig, ax, r=0.51, s=1):
"""
Parameters
----------
fig, ax : figure and axes handle from matplotlib
r : height/width ratio
s : scaling of font size
Example
-------
from mydefaults import mydefaults
fig, ax = mpl.pyplot.subplots()
fig, ax = mydefaults(fig, ax)
"""
#fig, ax = mpl.pyplot.subplots()
# Specify fig size
# fig.set_size_inches(s*(13.2/2.54), s*r*(13.2/2.54), forward=True)
# Use tex and correct font
#mpl.rcParams['font.family'] = 'Serif'
mpl.rcParams['font.serif'] = ['computer modern roman']
#mpl.rcParams['text.usetex'] = True # makes zeros bold?
mpl.rcParams['font.size'] = 11
mpl.rcParams['font.weight'] = 'normal'
# MATLAB default (see MATLAB Axes Properties documentation)
mpl.rcParams['axes.titlesize'] = 1.1*11
mpl.rcParams['axes.titleweight'] = 'bold'
# MATLAB default (see MATLAB Axes Properties documentation)
mpl.rcParams['axes.labelsize'] = 1.1*11
mpl.rcParams['axes.labelweight'] = 'normal'
# MATLAB default (see MATLAB Axes Properties documentation)
mpl.rcParams['legend.fontsize'] = 0.9*11
# remove margine padding on axis
mpl.rcParams['axes.xmargin'] = 0
mpl.rcParams['axes.ymargin'] = 0
# switch tick direction like MATLAB
mpl.rcParams['xtick.direction'] = 'in'
mpl.rcParams['ytick.direction'] = 'in'
mpl.pyplot.tight_layout(pad=1.3) # padding as fraction of font size
if isinstance(ax, tuple) or isinstance(ax, numpy.ndarray):
for axi in ax:
axi.tick_params(axis='both', which='both', direction='in')
else:
ax.tick_params(axis='both', which='both', direction='in')
# Save fig with transparent background
mpl.rcParams['savefig.transparent'] = True
# Make legend frame border black and face white
mpl.rcParams['legend.edgecolor'] = 'k'
mpl.rcParams['legend.facecolor'] = 'w'
mpl.rcParams['legend.framealpha'] = 1
# Change colorcycle to MATLABS
c = mpl.cycler(color=['#0072BD', '#D95319', '#EDB120', '#4DBEEE', '#77AC30', '#7E2F8E', '#A2142F'])
if isinstance(ax, tuple) or isinstance(ax, numpy.ndarray):
for axi in ax:
axi.set_prop_cycle(c)
else:
ax.set_prop_cycle(c)
# mpl.rcParams['axes.prop_cycle'] = c # doesnt work?
return fig, ax