-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
56 lines (47 loc) · 1.91 KB
/
util.py
File metadata and controls
56 lines (47 loc) · 1.91 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
import warnings
def setopts(opts, kwargs):
import matplotlib
for key, value in kwargs.items():
if 'rcParams' in kwargs and key == 'rcParams':
continue
if key in opts:
opts[key] = value
else:
warnings.warn('Warning: Ignoring invalid keyword option "%s".' % key, SyntaxWarning)
# Override or add rcParams
if 'rcParams' in kwargs:
for key, value in kwargs['rcParams'].items():
opts['rcParams'][key] = kwargs['rcParams'][key]
if opts['backend'] != 'default':
try:
matplotlib.use(opts['backend'], force=True)
except:
matplotlib.use(matplotlib.get_backend(), force=True)
warnings.warn('Warning: matplotlib(' + opts['backend'] + \
') call failed. Using default backend of ' +
matplotlib.get_backend(), SyntaxWarning)
style = opts['style']
import matplotlib.style
rclib = matplotlib.style.library
if style in matplotlib.style.available:
# rc parameters for style that differ from default
rcstyle = dict(rclib[style])
else:
rcstyle = dict(rclib['fast'])
warnings.warn('style "' + style + \
'" is not in list of known styles: ' + \
str(matplotlib.style.available) + \
'. Using style=fast', SyntaxWarning)
# Get default rc parameters
rc = dict(matplotlib.rcParamsDefault)
# Override default rc value with a style value
for key in rcstyle:
rc[key] = rcstyle[key]
# Override default rc style values with user-provided values
for key in opts['rcParams']:
if key in rc: # Is an actual rc parameter
rc[key] = opts['rcParams'][key]
else:
warnings.warn('rc parameter "' + key + '" is not in a known rc parameter.', SyntaxWarning)
opts['rcParams'] = rc
return opts