Skip to content

Commit 7bf58e3

Browse files
committed
version change + test case + incoporation of suggestions on stepwhere and range(..)
1 parent 254518a commit 7bf58e3

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 7, 'alpha', 11)
2+
version_info = (0, 12, 7, 'alpha', 12)
33

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

src/mplfinance/plotting.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,12 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config):
910910
alpha = apdict['alpha']
911911
ax.plot(xdates,ydata,linestyle=ls,color=color,linewidth=width,alpha=alpha)
912912
elif aptype == 'step':
913-
where = apdict['where']
913+
stepwhere = apdict['stepwhere']
914914
ls = apdict['linestyle']
915915
color = apdict['color']
916916
width = apdict['width'] if apdict['width'] is not None else 1.6*config['_width_config']['line_width']
917917
alpha = apdict['alpha']
918-
ax.step(range(len(xdates)),ydata,where = where,linestyle=ls,color=color,linewidth=width,alpha=alpha)
918+
ax.step(xdates,ydata,where = stepwhere,linestyle=ls,color=color,linewidth=width,alpha=alpha)
919919
else:
920920
raise ValueError('addplot type "'+str(aptype)+'" NOT yet supported.')
921921

@@ -1003,7 +1003,7 @@ def _valid_addplot_kwargs():
10031003

10041004
valid_linestyles = ('-','solid','--','dashed','-.','dashdot','.','dotted',None,' ','')
10051005
valid_types = ('line','scatter','bar', 'ohlc', 'candle','step')
1006-
valid_wheres = ('pre','post','mid')
1006+
valid_stepwheres = ('pre','post','mid')
10071007

10081008
vkwargs = {
10091009
'scatter' : { 'Default' : False,
@@ -1064,8 +1064,8 @@ def _valid_addplot_kwargs():
10641064
'yscale' : { 'Default' : None,
10651065
'Validator' : lambda value: _yscale_validator(value) },
10661066

1067-
'where' : { 'Default' : 'pre',
1068-
'Validator' : lambda value : value in valid_wheres },
1067+
'stepwhere' : { 'Default' : 'pre',
1068+
'Validator' : lambda value : value in valid_stepwheres },
10691069
}
10701070

10711071
_validate_vkwargs_dict(vkwargs)

tests/reference_images/addplot11.png

35.8 KB
Loading

tests/test_addplot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,28 @@ def test_addplot10(bolldata):
329329
print('result=',result)
330330
assert result is None
331331

332+
def test_addplot11(bolldata):
333+
334+
df = bolldata.iloc[50:130,]
335+
336+
fname = base+'11.png'
337+
tname = os.path.join(tdir,fname)
338+
rname = os.path.join(refd,fname)
339+
340+
df['trend'] = 0
341+
df.loc[df['Close'] < df['Open'], 'trend'] = - 1
342+
df.loc[df['Close'] > df['Open'], 'trend'] = 1
343+
ap = mpf.make_addplot(df['trend'],panel=1,type='step',ylabel='simple trend')
344+
mpf.plot(df,ylabel='OHLC',addplot=ap,savefig=tname)
345+
346+
tsize = os.path.getsize(tname)
347+
print(glob.glob(tname),'[',tsize,'bytes',']')
348+
349+
rsize = os.path.getsize(rname)
350+
print(glob.glob(rname),'[',rsize,'bytes',']')
351+
352+
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
353+
if result is not None:
354+
print('result=',result)
355+
assert result is None
356+

0 commit comments

Comments
 (0)