|
| 1 | +import os as os |
| 2 | +import pandas as pd |
| 3 | +import mplfinance as mpf |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +from matplotlib.testing.compare import compare_images |
| 6 | + |
| 7 | +print('pd.__version__ =',pd.__version__ ) # for the record |
| 8 | +print('mpf.__version__ =',mpf.__version__) # for the record |
| 9 | +print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record |
| 10 | + |
| 11 | +import subprocess |
| 12 | +pwd = subprocess.run(['pwd'], stdout=subprocess.PIPE) |
| 13 | +print('pwd.stdout=',pwd.stdout) |
| 14 | + |
| 15 | + |
| 16 | +df = pd.read_csv('../data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True) |
| 17 | +print('df.shape=' , df.shape ) |
| 18 | +print('df.head(3)=', df.head(3)) |
| 19 | +print('df.tail(3)=', df.tail(3)) |
| 20 | + |
| 21 | +prefix='addplot' |
| 22 | +tdir='test_images/' |
| 23 | +refd='reference_images/' |
| 24 | +#os.system('rm -f '+tdir+prefix+'*.jpg') |
| 25 | +os.system('rm -f '+tdir+prefix+'*.png') |
| 26 | + |
| 27 | +IMGCOMP_TOLERANCE = 7.0 |
| 28 | + |
| 29 | +# ---- Test 01 ----- |
| 30 | + |
| 31 | +fname=prefix+'01.png' |
| 32 | +mpf.plot(df,volume=True,savefig=tdir+fname) |
| 33 | + |
| 34 | +os.system('ls -l '+tdir+fname) |
| 35 | + |
| 36 | +result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE) |
| 37 | +if result is not None: |
| 38 | + print('result=',result) |
| 39 | +assert result is None |
| 40 | + |
| 41 | +# ---- Test 02 ----- |
| 42 | + |
| 43 | +fname=prefix+'02.png' |
| 44 | +apdict = mpf.make_addplot(df['LowerB']) |
| 45 | +mpf.plot(df,volume=True,addplot=apdict,savefig=tdir+fname) |
| 46 | + |
| 47 | +os.system('ls -l '+tdir+fname) |
| 48 | + |
| 49 | +result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE) |
| 50 | +if result is not None: |
| 51 | + print('result=',result) |
| 52 | +assert result is None |
0 commit comments