forked from matplotlib/mplfinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmplrcputils.py
executable file
·87 lines (73 loc) · 2.22 KB
/
mplrcputils.py
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
#!/usr/bin/env python
"""
rcparams utilities
"""
import pandas as pd
import matplotlib.pyplot as plt
import sys
__author__ = "Daniel Goldfarb"
__version__ = "0.1.0"
__license__ = "MIT"
def rcParams_to_df(rcp,name=None):
keys = []
vals = []
for item in rcp:
keys.append(item)
vals.append(rcp[item])
df = pd.DataFrame(vals,index=pd.Index(keys,name='rcParamsKey'))
if name is not None:
df.columns = [name]
else:
df.columns = ['Value']
return df
def compare_styles(s1,s2):
with plt.rc_context():
plt.style.use('default')
plt.style.use(s1)
df1 = rcParams_to_df(plt.rcParams,name=s1)
with plt.rc_context():
plt.style.use('default')
plt.style.use(s2)
df2 = rcParams_to_df(plt.rcParams,name=s2)
df = pd.concat([df1,df2],axis=1)
dif = df[df[s1] != df[s2]].dropna(how='all')
return (dif,df,df1,df2)
def main():
""" Main entry point of the app """
def usage():
print('\n Usage: rcparams <command> <arguments> \n')
print(' Available commands: ')
print(' rcparams find <findstring>')
print(' rcparams compare <style1> <style2>')
print('')
exit(1)
commands = ('find','compare')
if len(sys.argv) < 3 :
print('\n Too few arguments!')
usage()
command = sys.argv[1]
if command not in commands:
print('\n Unrecognized command \"'+command+'\"')
usage()
if command == 'find':
findstr = sys.argv[2]
df = rcParams_to_df(plt.rcParams)
if findstr == '--all':
for key in df.index:
print(key+':',df.loc[key,'Value'])
else:
print(df[df.index.str.contains(findstr)])
elif command == 'compare':
if len(sys.argv) < 4 :
print('\n Need two styles to compare!')
usage()
style1 = sys.argv[2]
style2 = sys.argv[3]
dif,df,df1,df2 = compare_styles(style1,style2)
print('\n==== dif ====\n',dif)
else:
print('\n Unrecognized command \"'+command+'\"')
usage()
if __name__ == "__main__":
""" This is executed when run from the command line """
main()