Skip to content

Commit 1681608

Browse files
Merge pull request #369 from pankaj3009/master
Feature Request: Ability to plot step /staircase lines implemented Is…
2 parents 43600c3 + a69faab commit 1681608

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
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', 15)
2+
version_info = (0, 12, 7, 'alpha', 16)
33

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

src/mplfinance/plotting.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,13 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config):
924924
width = apdict['width'] if apdict['width'] is not None else 1.6*config['_width_config']['line_width']
925925
alpha = apdict['alpha']
926926
ax.plot(xdates,ydata,linestyle=ls,color=color,linewidth=width,alpha=alpha)
927+
elif aptype == 'step':
928+
stepwhere = apdict['stepwhere']
929+
ls = apdict['linestyle']
930+
color = apdict['color']
931+
width = apdict['width'] if apdict['width'] is not None else 1.6*config['_width_config']['line_width']
932+
alpha = apdict['alpha']
933+
ax.step(xdates,ydata,where = stepwhere,linestyle=ls,color=color,linewidth=width,alpha=alpha)
927934
else:
928935
raise ValueError('addplot type "'+str(aptype)+'" NOT yet supported.')
929936

@@ -1010,7 +1017,8 @@ def _auto_secondary_y( panels, panid, ylo, yhi ):
10101017
def _valid_addplot_kwargs():
10111018

10121019
valid_linestyles = ('-','solid','--','dashed','-.','dashdot','.','dotted',None,' ','')
1013-
valid_types = ('line','scatter','bar', 'ohlc', 'candle')
1020+
valid_types = ('line','scatter','bar', 'ohlc', 'candle','step')
1021+
valid_stepwheres = ('pre','post','mid')
10141022

10151023
vkwargs = {
10161024
'scatter' : { 'Default' : False,
@@ -1070,6 +1078,9 @@ def _valid_addplot_kwargs():
10701078

10711079
'yscale' : { 'Default' : None,
10721080
'Validator' : lambda value: _yscale_validator(value) },
1081+
1082+
'stepwhere' : { 'Default' : 'pre',
1083+
'Validator' : lambda value : value in valid_stepwheres },
10731084
}
10741085

10751086
_validate_vkwargs_dict(vkwargs)

tests/reference_images/addplot11.png

35.2 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[50:130].copy()
335+
336+
fname = base+'11.png'
337+
tname = os.path.join(tdir,fname)
338+
rname = os.path.join(refd,fname)
339+
340+
df.loc[:,'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)