Skip to content

Commit 0b53c79

Browse files
allow scale width adjustment in style
1 parent 624d161 commit 0b53c79

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

examples/scratch_pad/issues/issue#241_loop_all_styles.ipynb

Lines changed: 11 additions & 6 deletions
Large diffs are not rendered by default.

src/mplfinance/_styledata/tradingview.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'alpha' : 1.0,
1111
'volume_alpha': 0.65,
1212
},
13+
#scale_width_adjustment = { 'volume': 0.8 },
1314
mavcolors = ['#2962ff','#2962ff',],
1415
y_on_right = True,
1516
gridcolor = None,

src/mplfinance/_widths.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ def _valid_update_width_kwargs():
102102

103103
return vkwargs
104104

105+
def _scale_width_config(scale,width_config):
106+
if scale['volume'] is not None:
107+
width_config['volume_width'] *= scale['volume']
108+
if scale['ohlc'] is not None:
109+
width_config['ohlc_ticksize'] *= scale['ohlc']
110+
if scale['candle'] is not None:
111+
width_config['candle_width'] *= scale['candle']
112+
if scale['lines'] is not None:
113+
width_config['line_width'] *= scale['lines']
114+
if scale['volume_linewidth'] is not None:
115+
width_config['volume_linewidth'] *= scale['volume_linewidth']
116+
if scale['ohlc_linewidth'] is not None:
117+
width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth']
118+
if scale['candle_linewidth'] is not None:
119+
width_config['candle_linewidth'] *= scale['candle_linewidth']
105120

106121
def _determine_width_config( xdates, config ):
107122
'''
@@ -138,23 +153,13 @@ def _determine_width_config( xdates, config ):
138153
width_config['candle_linewidth'] = _dfinterpolate(_widths,datalen,'clw')
139154
width_config['line_width' ] = _dfinterpolate(_widths,datalen,'lw')
140155

141-
if config['scale_width_adjustment'] is not None:
156+
if 'scale_width_adjustment' in config['style']:
157+
scale = _process_kwargs(config['style']['scale_width_adjustment'],_valid_scale_width_kwargs())
158+
_scale_width_config(scale,width_config)
142159

160+
if config['scale_width_adjustment'] is not None:
143161
scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs())
144-
if scale['volume'] is not None:
145-
width_config['volume_width'] *= scale['volume']
146-
if scale['ohlc'] is not None:
147-
width_config['ohlc_ticksize'] *= scale['ohlc']
148-
if scale['candle'] is not None:
149-
width_config['candle_width'] *= scale['candle']
150-
if scale['lines'] is not None:
151-
width_config['line_width'] *= scale['lines']
152-
if scale['volume_linewidth'] is not None:
153-
width_config['volume_linewidth'] *= scale['volume_linewidth']
154-
if scale['ohlc_linewidth'] is not None:
155-
width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth']
156-
if scale['candle_linewidth'] is not None:
157-
width_config['candle_linewidth'] *= scale['candle_linewidth']
162+
_scale_width_config(scale,width_config)
158163

159164
if config['update_width_config'] is not None:
160165

0 commit comments

Comments
 (0)