Skip to content

Support marketcolors kwarg in make_addplot() #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/scratch_pad/iss466_pr471.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pandas as pd
import mplfinance as mpf

aapldf = pd.read_csv('../data/yahoofinance-AAPL-20040819-20180120.csv',index_col=0,parse_dates=True).iloc[-61:-1]
googdf = pd.read_csv('../data/yahoofinance-GOOG-20040819-20180120.csv',index_col=0,parse_dates=True).iloc[-61:-1]

mcblue = mpf.make_marketcolors(base_mpf_style='default',up='b',down='b',ohlc='b')
mcgreen = mpf.make_marketcolors(base_mpf_style='default',up='limegreen',down='limegreen',ohlc='limegreen')

sblue = mpf.make_mpf_style(base_mpf_style='default',marketcolors=mcblue)

ap = mpf.make_addplot(googdf,type='candle',marketcolors=mcgreen)
mpf.plot(aapldf,type='candle',style=sblue,returnfig=True,addplot=ap)
mpf.show()
2 changes: 1 addition & 1 deletion src/mplfinance/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version_info = (0, 12, 8, 'beta', 5)
version_info = (0, 12, 8, 'beta', 6)

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

Expand Down
17 changes: 14 additions & 3 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from mplfinance._arg_validators import _alines_validator, _tlines_validator
from mplfinance._arg_validators import _scale_padding_validator, _yscale_validator
from mplfinance._arg_validators import _valid_panel_id, _check_for_external_axes
from mplfinance._arg_validators import _xlim_validator, _mco_validator
from mplfinance._arg_validators import _xlim_validator, _mco_validator, _is_marketcolor_object

from mplfinance._panels import _build_panels
from mplfinance._panels import _set_ticks_on_bottom_panel_only
Expand Down Expand Up @@ -865,7 +865,15 @@ def _addplot_collections(panid,panels,apdict,xdates,config):
if not isinstance(apdata,pd.DataFrame):
raise TypeError('addplot type "'+aptype+'" MUST be accompanied by addplot data of type `pd.DataFrame`')
d,o,h,l,c,v = _check_and_prepare_data(apdata,config)
collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,config['style'])

mc = apdict['marketcolors']
if _is_marketcolor_object(mc):
apstyle = config['style'].copy()
apstyle['marketcolors'] = mc
else:
apstyle = config['style']

collections = _construct_mpf_collections(aptype,d,xdates,o,h,l,c,v,config,apstyle)

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

'stepwhere' : { 'Default' : 'pre',
'Validator' : lambda value : value in valid_stepwheres },
'Validator' : lambda value : value in valid_stepwheres },

'marketcolors' : { 'Default' : None, # use 'style' for default, instead.
'Validator' : lambda value: _is_marketcolor_object(value) },
}

_validate_vkwargs_dict(vkwargs)
Expand Down