Skip to content

Commit 220b693

Browse files
author
Adriana Miyazaki
authored
Update plotting.py
Add possibility to plot multiple candle plots with different colors, using make_marketcolors with make_addplot function. The code is from DanielGoldfarb, and it's on website: https://gitmemory.com/DanielGoldfarb
1 parent d777f43 commit 220b693

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/mplfinance/plotting.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,15 @@ def _addplot_collections(panid,panels,apdict,xdates,config):
858858
if not isinstance(apdata,pd.DataFrame):
859859
raise TypeError('addplot type "'+aptype+'" MUST be accompanied by addplot data of type `pd.DataFrame`')
860860
d,o,h,l,c,v = _check_and_prepare_data(apdata,config)
861-
collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,config['style'])
861+
862+
mc = apdict['marketcolors']
863+
if isinstance(mc,dict):
864+
apstyle = config['style'].copy()
865+
apstyle['marketcolors'] = mc
866+
else:
867+
apstyle = config['style']
868+
869+
collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,apstyle)
862870

863871
if not external_axes_mode:
864872
lo = math.log(max(math.fabs(np.nanmin(l)),1e-7),10) - 0.5
@@ -1087,7 +1095,10 @@ def _valid_addplot_kwargs():
10871095
'Validator' : lambda value: _yscale_validator(value) },
10881096

10891097
'stepwhere' : { 'Default' : 'pre',
1090-
'Validator' : lambda value : value in valid_stepwheres },
1098+
'Validator' : lambda value : value in valid_stepwheres },
1099+
1100+
'marketcolors' : { 'Default' : None, # use 'style' for default, instead.
1101+
'Validator' : lambda value: isinstance(value,dict) },
10911102
}
10921103

10931104
_validate_vkwargs_dict(vkwargs)

0 commit comments

Comments
 (0)