Skip to content

Added multi fill_between #519

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 2 commits into from
May 10, 2022
Merged
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
37 changes: 24 additions & 13 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ def _valid_plot_kwargs():
'Description' : 'fill between specification as y-value, or sequence of'+
' y-values, or dict containing key "y1" plus any additional'+
' kwargs for `fill_between()`',
'Validator' : lambda value: _num_or_seq_of_num(value) or
'Validator' : lambda value: _num_or_seq_of_num(value) or
(isinstance(value,dict) and 'y1' in value and
_num_or_seq_of_num(value['y1'])) },
_num_or_seq_of_num(value['y1'])) or
isinstance(value,(list,tuple))},

'tight_layout' : { 'Default' : False,
'Description' : 'True|False implement tight layout (minimal padding around Figure)'+
Expand Down Expand Up @@ -707,18 +708,28 @@ def plot( data, **kwargs ):
if config['fill_between'] is not None and not external_axes_mode:
fb = config['fill_between']
panid = config['main_panel']
if isinstance(fb,dict):
if 'x' in fb:
raise ValueError('fill_between dict may not contain `x`')
if 'panel' in fb:
panid = fb['panel']
del fb['panel']
if isinstance(fb,list):
for element in fb:
if 'panel' in element:
panind = element['panel']
del element['panel']

element['x'] = xdates
ax = panels.at[panid,'axes'][0]
ax.fill_between(**element)
else:
fb = dict(y1=fb)
fb['x'] = xdates
ax = panels.at[panid,'axes'][0]
ax.fill_between(**fb)

if isinstance(fb,dict):
if 'x' in fb:
raise ValueError('fill_between dict may not contain `x`')
if 'panel' in fb:
panid = fb['panel']
del fb['panel']
else:
fb = dict(y1=fb)
fb['x'] = xdates
ax = panels.at[panid,'axes'][0]
ax.fill_between(**fb)

# put the primary axis on one side,
# and the twinx() on the "other" side:
if not external_axes_mode:
Expand Down