Skip to content

Commit 7a9eb24

Browse files
Merge branch 'enh-lines' of github.com:DanielGoldfarb/mplfinance into enh-lines
2 parents fe56f58 + bbb41f1 commit 7a9eb24

File tree

9 files changed

+266
-0
lines changed

9 files changed

+266
-0
lines changed

tests/reference_images/alines01.png

35.5 KB
Loading

tests/reference_images/hlines01.png

34.6 KB
Loading

tests/reference_images/hlines02.png

34.8 KB
Loading

tests/reference_images/vlines01.png

34.7 KB
Loading

tests/reference_images/vlines02.png

34.6 KB
Loading

tests/reference_images/vlines03.png

54.8 KB
Loading

tests/test_alines.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import os.path
3+
import glob
4+
import mplfinance as mpf
5+
import matplotlib.pyplot as plt
6+
from matplotlib.testing.compare import compare_images
7+
8+
print('mpf.__version__ =',mpf.__version__) # for the record
9+
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
10+
11+
base='alines'
12+
tdir = os.path.join('tests','test_images')
13+
refd = os.path.join('tests','reference_images')
14+
15+
globpattern = os.path.join(tdir,base+'*.png')
16+
oldtestfiles = glob.glob(globpattern)
17+
18+
for fn in oldtestfiles:
19+
try:
20+
os.remove(fn)
21+
except:
22+
print('Error removing file "'+fn+'"')
23+
24+
IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
25+
# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
26+
27+
def test_alines01(bolldata):
28+
29+
df = bolldata
30+
31+
fname = base+'01.png'
32+
tname = os.path.join(tdir,fname)
33+
rname = os.path.join(refd,fname)
34+
segments1 = [('2011-09-13', 115.),('2012-02-06', 135.)]
35+
fig_axis = mpf.plot(
36+
df,volume=True,savefig=tname,returnfig=True,alines=segments1
37+
)
38+
39+
plt.close(fig_axis[0])
40+
41+
tsize = os.path.getsize(tname)
42+
print(glob.glob(tname),'[',tsize,'bytes',']')
43+
44+
rsize = os.path.getsize(rname)
45+
print(glob.glob(rname),'[',rsize,'bytes',']')
46+
47+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
48+
if result is not None:
49+
print('result=',result)
50+
assert result is None
51+

tests/test_hlines.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import os
2+
import os.path
3+
import glob
4+
import mplfinance as mpf
5+
import matplotlib.pyplot as plt
6+
from matplotlib.testing.compare import compare_images
7+
8+
print('mpf.__version__ =',mpf.__version__) # for the record
9+
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
10+
11+
base='hlines'
12+
tdir = os.path.join('tests','test_images')
13+
refd = os.path.join('tests','reference_images')
14+
15+
globpattern = os.path.join(tdir,base+'*.png')
16+
oldtestfiles = glob.glob(globpattern)
17+
18+
for fn in oldtestfiles:
19+
try:
20+
os.remove(fn)
21+
except:
22+
print('Error removing file "'+fn+'"')
23+
24+
IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
25+
# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
26+
27+
def test_hlines01(bolldata):
28+
29+
df = bolldata
30+
31+
fname = base+'01.png'
32+
tname = os.path.join(tdir,fname)
33+
rname = os.path.join(refd,fname)
34+
35+
fig_axis = mpf.plot(
36+
df,volume=True,savefig=tname,returnfig=True,hlines=[120]
37+
)
38+
plt.close(fig_axis[0])
39+
40+
tsize = os.path.getsize(tname)
41+
print(glob.glob(tname),'[',tsize,'bytes',']')
42+
43+
rsize = os.path.getsize(rname)
44+
print(glob.glob(rname),'[',rsize,'bytes',']')
45+
46+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
47+
if result is not None:
48+
print('result=',result)
49+
assert result is None
50+
51+
def test_hlines02(bolldata):
52+
df = bolldata
53+
54+
fname = base+'02.png'
55+
tname = os.path.join(tdir,fname)
56+
rname = os.path.join(refd,fname)
57+
58+
fig_axis = mpf.plot(
59+
df,
60+
type='ohlc',
61+
volume=True,
62+
savefig=tname,
63+
returnfig=True,
64+
hlines=dict(hlines=[120.000001, 130.0],linestyle='-.',colors='g')
65+
)
66+
plt.close(fig_axis[0])
67+
68+
tsize = os.path.getsize(tname)
69+
print(glob.glob(tname),'[',tsize,'bytes',']')
70+
71+
rsize = os.path.getsize(rname)
72+
print(glob.glob(rname),'[',rsize,'bytes',']')
73+
74+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
75+
if result is not None:
76+
print('result=',result)
77+
assert result is None
78+
#
79+
#
80+
# def test_vlines03(bolldata):
81+
# df = bolldata
82+
#
83+
# fname = base+'03.png'
84+
# tname = os.path.join(tdir,fname)
85+
# rname = os.path.join(refd,fname)
86+
#
87+
# vl = dict(vlines='02-06-2012',linestyle='-.',colors='g')
88+
# fig_axis = mpf.plot(
89+
# df,
90+
# type='pnf',
91+
# vlines=vl,
92+
# savefig=tname,
93+
# pointnfig_params=dict(box_size=1.),
94+
# returnfig=True
95+
# )
96+
# plt.close(fig_axis[0])
97+
#
98+
# tsize = os.path.getsize(tname)
99+
# print(glob.glob(tname),'[',tsize,'bytes',']')
100+
#
101+
# rsize = os.path.getsize(rname)
102+
# print(glob.glob(rname),'[',rsize,'bytes',']')
103+
#
104+
# result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
105+
# if result is not None:
106+
# print('result=',result)
107+
# assert result is None
108+
#
109+
#

tests/test_vlines.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import os
2+
import os.path
3+
import glob
4+
import mplfinance as mpf
5+
import matplotlib.pyplot as plt
6+
from matplotlib.testing.compare import compare_images
7+
8+
print('mpf.__version__ =',mpf.__version__) # for the record
9+
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
10+
11+
base='vlines'
12+
tdir = os.path.join('tests','test_images')
13+
refd = os.path.join('tests','reference_images')
14+
15+
globpattern = os.path.join(tdir,base+'*.png')
16+
oldtestfiles = glob.glob(globpattern)
17+
18+
for fn in oldtestfiles:
19+
try:
20+
os.remove(fn)
21+
except:
22+
print('Error removing file "'+fn+'"')
23+
24+
IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
25+
# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
26+
27+
def test_vlines01(bolldata):
28+
29+
df = bolldata
30+
31+
fname = base+'01.png'
32+
tname = os.path.join(tdir,fname)
33+
rname = os.path.join(refd,fname)
34+
35+
fig_axis = mpf.plot(
36+
df,volume=True,savefig=tname,returnfig=True,vlines=['2011-09-13']
37+
)
38+
plt.close(fig_axis[0])
39+
40+
tsize = os.path.getsize(tname)
41+
print(glob.glob(tname),'[',tsize,'bytes',']')
42+
43+
rsize = os.path.getsize(rname)
44+
print(glob.glob(rname),'[',rsize,'bytes',']')
45+
46+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
47+
if result is not None:
48+
print('result=',result)
49+
assert result is None
50+
51+
def test_vlines02(bolldata):
52+
df = bolldata
53+
54+
fname = base+'02.png'
55+
tname = os.path.join(tdir,fname)
56+
rname = os.path.join(refd,fname)
57+
58+
fig_axis = mpf.plot(
59+
df,
60+
volume=True,
61+
savefig=tname,
62+
returnfig=True,
63+
vlines=['2011-09-13', '2012-02-06', '2011-07-01', '2012-06-28']
64+
)
65+
plt.close(fig_axis[0])
66+
67+
tsize = os.path.getsize(tname)
68+
print(glob.glob(tname),'[',tsize,'bytes',']')
69+
70+
rsize = os.path.getsize(rname)
71+
print(glob.glob(rname),'[',rsize,'bytes',']')
72+
73+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
74+
if result is not None:
75+
print('result=',result)
76+
assert result is None
77+
78+
79+
def test_vlines03(bolldata):
80+
df = bolldata
81+
82+
fname = base+'03.png'
83+
tname = os.path.join(tdir,fname)
84+
rname = os.path.join(refd,fname)
85+
86+
vl = dict(vlines='02-06-2012',linestyle='-.',colors='g')
87+
fig_axis = mpf.plot(
88+
df,
89+
type='pnf',
90+
vlines=vl,
91+
savefig=tname,
92+
returnfig=True
93+
)
94+
plt.close(fig_axis[0])
95+
96+
tsize = os.path.getsize(tname)
97+
print(glob.glob(tname),'[',tsize,'bytes',']')
98+
99+
rsize = os.path.getsize(rname)
100+
print(glob.glob(rname),'[',rsize,'bytes',']')
101+
102+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
103+
if result is not None:
104+
print('result=',result)
105+
assert result is None
106+

0 commit comments

Comments
 (0)