Skip to content

Commit 918e31f

Browse files
committedJul 10, 2020
add scripts for which rcp_to_df.py was a precursor
1 parent a4eb33a commit 918e31f

File tree

4 files changed

+175
-13
lines changed

4 files changed

+175
-13
lines changed
 

‎examples/scratch_pad/rcp_to_df.py

-12
This file was deleted.

‎scripts/mplrcputils.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python
2+
"""
3+
rcparams utilities
4+
"""
5+
6+
import pandas as pd
7+
import matplotlib.pyplot as plt
8+
import sys
9+
10+
__author__ = "Daniel Goldfarb"
11+
__version__ = "0.1.0"
12+
__license__ = "MIT"
13+
14+
def rcParams_to_df(rcp,name=None):
15+
keys = []
16+
vals = []
17+
for item in rcp:
18+
keys.append(item)
19+
vals.append(rcp[item])
20+
df = pd.DataFrame(vals,index=pd.Index(keys,name='rcParamsKey'))
21+
if name is not None:
22+
df.columns = [name]
23+
else:
24+
df.columns = ['Value']
25+
return df
26+
27+
def compare_styles(s1,s2):
28+
with plt.rc_context():
29+
plt.style.use('default')
30+
plt.style.use(s1)
31+
df1 = rcParams_to_df(plt.rcParams,name=s1)
32+
33+
with plt.rc_context():
34+
plt.style.use('default')
35+
plt.style.use(s2)
36+
df2 = rcParams_to_df(plt.rcParams,name=s2)
37+
38+
df = pd.concat([df1,df2],axis=1)
39+
dif = df[df[s1] != df[s2]].dropna(how='all')
40+
return (dif,df,df1,df2)
41+
42+
def main():
43+
""" Main entry point of the app """
44+
def usage():
45+
print('\n Usage: rcparams <command> <arguments> \n')
46+
print(' Available commands: ')
47+
print(' rcparams find <findstring>')
48+
print(' rcparams compare <style1> <style2>')
49+
print('')
50+
exit(1)
51+
commands = ('find','compare')
52+
53+
if len(sys.argv) < 3 :
54+
print('\n Too few arguments!')
55+
usage()
56+
57+
command = sys.argv[1]
58+
if command not in commands:
59+
print('\n Unrecognized command \"'+command+'\"')
60+
usage()
61+
62+
if command == 'find':
63+
findstr = sys.argv[2]
64+
df = rcParams_to_df(plt.rcParams)
65+
if findstr == '--all':
66+
for key in df.index:
67+
print(key+':',df.loc[key,'Value'])
68+
else:
69+
print(df[df.index.str.contains(findstr)])
70+
71+
elif command == 'compare':
72+
if len(sys.argv) < 4 :
73+
print('\n Need two styles to compare!')
74+
usage()
75+
style1 = sys.argv[2]
76+
style2 = sys.argv[3]
77+
dif,df,df1,df2 = compare_styles(style1,style2)
78+
print('\n==== dif ====\n',dif)
79+
80+
else:
81+
print('\n Unrecognized command \"'+command+'\"')
82+
usage()
83+
84+
85+
if __name__ == "__main__":
86+
""" This is executed when run from the command line """
87+
main()

‎scripts/rcparams

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python
2+
"""
3+
rcparams utilities
4+
"""
5+
6+
import pandas as pd
7+
import matplotlib.pyplot as plt
8+
import sys
9+
10+
__author__ = "Daniel Goldfarb"
11+
__version__ = "0.1.0"
12+
__license__ = "MIT"
13+
14+
def rcParams_to_df(rcp,name=None):
15+
keys = []
16+
vals = []
17+
for item in rcp:
18+
keys.append(item)
19+
vals.append(rcp[item])
20+
df = pd.DataFrame(vals,index=pd.Index(keys,name='rcParamsKey'))
21+
if name is not None:
22+
df.columns = [name]
23+
else:
24+
df.columns = ['Value']
25+
return df
26+
27+
def compare_styles(s1,s2):
28+
with plt.rc_context():
29+
plt.style.use('default')
30+
plt.style.use(s1)
31+
df1 = rcParams_to_df(plt.rcParams,name=s1)
32+
33+
with plt.rc_context():
34+
plt.style.use('default')
35+
plt.style.use(s2)
36+
df2 = rcParams_to_df(plt.rcParams,name=s2)
37+
38+
df = pd.concat([df1,df2],axis=1)
39+
dif = df[df[s1] != df[s2]].dropna(how='all')
40+
return (dif,df,df1,df2)
41+
42+
def main():
43+
""" Main entry point of the app """
44+
def usage():
45+
print('\n Usage: rcparams <command> <arguments> \n')
46+
print(' Available commands: ')
47+
print(' rcparams find <findstring>')
48+
print(' rcparams compare <style1> <style2>')
49+
print('')
50+
exit(1)
51+
commands = ('find','compare')
52+
53+
if len(sys.argv) < 3 :
54+
print('\n Too few arguments!')
55+
usage()
56+
57+
command = sys.argv[1]
58+
if command not in commands:
59+
print('\n Unrecognized command \"'+command+'\"')
60+
usage()
61+
62+
if command == 'find':
63+
findstr = sys.argv[2]
64+
df = rcParams_to_df(plt.rcParams)
65+
if findstr == '--all':
66+
for key in df.index:
67+
print(key+':',df.loc[key,'Value'])
68+
else:
69+
print(df[df.index.str.contains(findstr)])
70+
71+
elif command == 'compare':
72+
if len(sys.argv) < 4 :
73+
print('\n Need two styles to compare!')
74+
usage()
75+
style1 = sys.argv[2]
76+
style2 = sys.argv[3]
77+
dif,df,df1,df2 = compare_styles(style1,style2)
78+
print('\n==== dif ====\n',dif)
79+
80+
else:
81+
print('\n Unrecognized command \"'+command+'\"')
82+
usage()
83+
84+
85+
if __name__ == "__main__":
86+
""" This is executed when run from the command line """
87+
main()

‎src/mplfinance/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 6, 'alpha', 3)
2+
version_info = (0, 12, 6, 'alpha', 4)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

0 commit comments

Comments
 (0)
Please sign in to comment.