Skip to content

Commit 43a6cb1

Browse files
committed
Added multi fill_between
Currently only one fill_between graph can be added to the plot. This patch aims to add the possibility of having an array of possible fill_between. Example: Currently the fill_between is as: args = {} args["fill_between"] = dict(y1=df[High],y2=df[Low],color=red...) fig, axes = mpf.plot(.....,**args) This patch also add the possibility of: args = {} args["fill_between"] = [ dict(y1=df1[High],y2=df1[Low],color=red...), dict(y1=df2[High],y2=df2[Low],color=green...) ]
1 parent fe985a0 commit 43a6cb1

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/mplfinance/plotting.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -707,18 +707,28 @@ def plot( data, **kwargs ):
707707
if config['fill_between'] is not None and not external_axes_mode:
708708
fb = config['fill_between']
709709
panid = config['main_panel']
710-
if isinstance(fb,dict):
711-
if 'x' in fb:
712-
raise ValueError('fill_between dict may not contain `x`')
713-
if 'panel' in fb:
714-
panid = fb['panel']
715-
del fb['panel']
710+
if isinstance(fb,list):
711+
for element in fb:
712+
if 'panel' in element:
713+
panind = element['panel']
714+
del element['panel']
715+
716+
element['x'] = xdates
717+
ax = panels.at[panid,'axes'][0]
718+
ax.fill_between(**element)
716719
else:
717-
fb = dict(y1=fb)
718-
fb['x'] = xdates
719-
ax = panels.at[panid,'axes'][0]
720-
ax.fill_between(**fb)
721-
720+
if isinstance(fb,dict):
721+
if 'x' in fb:
722+
raise ValueError('fill_between dict may not contain `x`')
723+
if 'panel' in fb:
724+
panid = fb['panel']
725+
del fb['panel']
726+
else:
727+
fb = dict(y1=fb)
728+
fb['x'] = xdates
729+
ax = panels.at[panid,'axes'][0]
730+
ax.fill_between(**fb)
731+
722732
# put the primary axis on one side,
723733
# and the twinx() on the "other" side:
724734
if not external_axes_mode:

0 commit comments

Comments
 (0)