Skip to content

Commit 1a0dcc5

Browse files
Merge pull request #471 from miya779/master
Support `marketcolors` kwarg in `make_addplot()`
2 parents 18fbd17 + 307096e commit 1a0dcc5

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

examples/scratch_pad/iss466_pr471.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pandas as pd
2+
import mplfinance as mpf
3+
4+
aapldf = pd.read_csv('../data/yahoofinance-AAPL-20040819-20180120.csv',index_col=0,parse_dates=True).iloc[-61:-1]
5+
googdf = pd.read_csv('../data/yahoofinance-GOOG-20040819-20180120.csv',index_col=0,parse_dates=True).iloc[-61:-1]
6+
7+
mcblue = mpf.make_marketcolors(base_mpf_style='default',up='b',down='b',ohlc='b')
8+
mcgreen = mpf.make_marketcolors(base_mpf_style='default',up='limegreen',down='limegreen',ohlc='limegreen')
9+
10+
sblue = mpf.make_mpf_style(base_mpf_style='default',marketcolors=mcblue)
11+
12+
ap = mpf.make_addplot(googdf,type='candle',marketcolors=mcgreen)
13+
mpf.plot(aapldf,type='candle',style=sblue,returnfig=True,addplot=ap)
14+
mpf.show()

src/mplfinance/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 8, 'beta', 5)
2+
version_info = (0, 12, 8, 'beta', 6)
33

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

src/mplfinance/plotting.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from mplfinance._arg_validators import _alines_validator, _tlines_validator
4040
from mplfinance._arg_validators import _scale_padding_validator, _yscale_validator
4141
from mplfinance._arg_validators import _valid_panel_id, _check_for_external_axes
42-
from mplfinance._arg_validators import _xlim_validator, _mco_validator
42+
from mplfinance._arg_validators import _xlim_validator, _mco_validator, _is_marketcolor_object
4343

4444
from mplfinance._panels import _build_panels
4545
from mplfinance._panels import _set_ticks_on_bottom_panel_only
@@ -865,7 +865,15 @@ def _addplot_collections(panid,panels,apdict,xdates,config):
865865
if not isinstance(apdata,pd.DataFrame):
866866
raise TypeError('addplot type "'+aptype+'" MUST be accompanied by addplot data of type `pd.DataFrame`')
867867
d,o,h,l,c,v = _check_and_prepare_data(apdata,config)
868-
collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,config['style'])
868+
869+
mc = apdict['marketcolors']
870+
if _is_marketcolor_object(mc):
871+
apstyle = config['style'].copy()
872+
apstyle['marketcolors'] = mc
873+
else:
874+
apstyle = config['style']
875+
876+
collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,apstyle)
869877

870878
if not external_axes_mode:
871879
lo = math.log(max(math.fabs(np.nanmin(l)),1e-7),10) - 0.5
@@ -1104,7 +1112,10 @@ def _valid_addplot_kwargs():
11041112
'Validator' : lambda value: _yscale_validator(value) },
11051113

11061114
'stepwhere' : { 'Default' : 'pre',
1107-
'Validator' : lambda value : value in valid_stepwheres },
1115+
'Validator' : lambda value : value in valid_stepwheres },
1116+
1117+
'marketcolors' : { 'Default' : None, # use 'style' for default, instead.
1118+
'Validator' : lambda value: _is_marketcolor_object(value) },
11081119
}
11091120

11101121
_validate_vkwargs_dict(vkwargs)

0 commit comments

Comments
 (0)