Skip to content

Commit 8501f81

Browse files
committed
add fill_between support for additional plot
1 parent fe985a0 commit 8501f81

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/mplfinance/plotting.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def plot( data, **kwargs ):
687687
aptype = apdict['type']
688688
if aptype == 'ohlc' or aptype == 'candle':
689689
ax = _addplot_collections(panid,panels,apdict,xdates,config)
690-
_addplot_apply_supplements(ax,apdict)
690+
_addplot_apply_supplements(ax,apdict,xdates)
691691
else:
692692
apdata = apdict['data']
693693
if isinstance(apdata,list) and not isinstance(apdata[0],(float,int)):
@@ -700,7 +700,7 @@ def plot( data, **kwargs ):
700700
for column in apdata:
701701
ydata = apdata.loc[:,column] if havedf else column
702702
ax = _addplot_columns(panid,panels,ydata,apdict,xdates,config)
703-
_addplot_apply_supplements(ax,apdict)
703+
_addplot_apply_supplements(ax,apdict,xdates)
704704

705705
# fill_between is NOT supported for external_axes_mode
706706
# (caller can easily call ax.fill_between() themselves).
@@ -1045,7 +1045,7 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config):
10451045

10461046
return ax
10471047

1048-
def _addplot_apply_supplements(ax,apdict):
1048+
def _addplot_apply_supplements(ax,apdict,xdates):
10491049
if (apdict['ylabel'] is not None):
10501050
ax.set_ylabel(apdict['ylabel'])
10511051
if apdict['ylim'] is not None:
@@ -1059,6 +1059,11 @@ def _addplot_apply_supplements(ax,apdict):
10591059
ax.set_yscale(yscale,**ysd)
10601060
elif isinstance(ysd,str):
10611061
ax.set_yscale(ysd)
1062+
# added by Wen
1063+
if "fill_between" in apdict and apdict['fill_between'] is not None:
1064+
fb = apdict['fill_between']
1065+
fb['x'] = xdates
1066+
ax.fill_between(**fb)
10621067

10631068
def _set_ylabels_side(ax_pri,ax_sec,primary_on_right):
10641069
# put the primary axis on one side,
@@ -1234,6 +1239,10 @@ def _valid_addplot_kwargs():
12341239
" style\'s marketcolors). For addplot `type='ohlc'`"+
12351240
" and type='candle'",
12361241
'Validator' : lambda value: _is_marketcolor_object(value) },
1242+
'fill_between': { 'Default' : None, # added by Wen
1243+
'Description' : " fill region",
1244+
'Validator' : lambda value: isinstance(value,dict) },
1245+
12371246
}
12381247

12391248
_validate_vkwargs_dict(vkwargs)

0 commit comments

Comments
 (0)