|
32 | 32 | from mplfinance import _styles
|
33 | 33 |
|
34 | 34 | from mplfinance._arg_validators import _check_and_prepare_data, _mav_validator
|
35 |
| -from mplfinance._arg_validators import _get_valid_plot_types |
| 35 | +from mplfinance._arg_validators import _get_valid_plot_types, _fill_between_validator |
36 | 36 | from mplfinance._arg_validators import _process_kwargs, _validate_vkwargs_dict
|
37 | 37 | from mplfinance._arg_validators import _kwarg_not_implemented, _bypass_kwarg_validation
|
38 | 38 | from mplfinance._arg_validators import _hlines_validator, _vlines_validator
|
@@ -304,9 +304,7 @@ def _valid_plot_kwargs():
|
304 | 304 | 'Description' : 'fill between specification as y-value, or sequence of'+
|
305 | 305 | ' y-values, or dict containing key "y1" plus any additional'+
|
306 | 306 | ' kwargs for `fill_between()`',
|
307 |
| - 'Validator' : lambda value: _num_or_seq_of_num(value) or |
308 |
| - (isinstance(value,dict) and 'y1' in value and |
309 |
| - _num_or_seq_of_num(value['y1'])) }, |
| 307 | + 'Validator' : _fill_between_validator }, |
310 | 308 |
|
311 | 309 | 'tight_layout' : { 'Default' : False,
|
312 | 310 | 'Description' : 'True|False implement tight layout (minimal padding around Figure)'+
|
@@ -705,19 +703,23 @@ def plot( data, **kwargs ):
|
705 | 703 | # fill_between is NOT supported for external_axes_mode
|
706 | 704 | # (caller can easily call ax.fill_between() themselves).
|
707 | 705 | if config['fill_between'] is not None and not external_axes_mode:
|
708 |
| - fb = config['fill_between'] |
709 |
| - panid = config['main_panel'] |
710 |
| - if isinstance(fb,dict): |
| 706 | + fblist = config['fill_between'] |
| 707 | + panid = config['main_panel'] |
| 708 | + if _num_or_seq_of_num(fblist): |
| 709 | + fblist = [dict(y1=fblist),] |
| 710 | + elif isinstance(fblist,dict): |
| 711 | + fblist = [fblist,] |
| 712 | + if not _list_of_dict(fblist): |
| 713 | + raise TypeError('Bad type for `fill_between` specifier.') |
| 714 | + for fb in fblist: |
711 | 715 | if 'x' in fb:
|
712 | 716 | raise ValueError('fill_between dict may not contain `x`')
|
713 | 717 | if 'panel' in fb:
|
714 | 718 | panid = fb['panel']
|
715 | 719 | del fb['panel']
|
716 |
| - else: |
717 |
| - fb = dict(y1=fb) |
718 |
| - fb['x'] = xdates |
719 |
| - ax = panels.at[panid,'axes'][0] |
720 |
| - ax.fill_between(**fb) |
| 720 | + fb['x'] = xdates |
| 721 | + ax = panels.at[panid,'axes'][0] |
| 722 | + ax.fill_between(**fb) |
721 | 723 |
|
722 | 724 | # put the primary axis on one side,
|
723 | 725 | # and the twinx() on the "other" side:
|
@@ -1061,9 +1063,13 @@ def _addplot_apply_supplements(ax,apdict,xdates):
|
1061 | 1063 | ax.set_yscale(ysd)
|
1062 | 1064 | # added by Wen
|
1063 | 1065 | 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) |
| 1066 | + fblist = apdict['fill_between'] |
| 1067 | + if isinstance(fblist,dict): |
| 1068 | + fblist = [fblist,] |
| 1069 | + if _list_of_dict(fblist): |
| 1070 | + for fb in fblist: |
| 1071 | + fb['x'] = xdates |
| 1072 | + ax.fill_between(**fb) |
1067 | 1073 |
|
1068 | 1074 | def _set_ylabels_side(ax_pri,ax_sec,primary_on_right):
|
1069 | 1075 | # put the primary axis on one side,
|
@@ -1241,7 +1247,7 @@ def _valid_addplot_kwargs():
|
1241 | 1247 | 'Validator' : lambda value: _is_marketcolor_object(value) },
|
1242 | 1248 | 'fill_between': { 'Default' : None, # added by Wen
|
1243 | 1249 | 'Description' : " fill region",
|
1244 |
| - 'Validator' : lambda value: isinstance(value,dict) }, |
| 1250 | + 'Validator' : _fill_between_validator }, |
1245 | 1251 |
|
1246 | 1252 | }
|
1247 | 1253 |
|
|
0 commit comments