Skip to content

Commit b0c509f

Browse files
Merge pull request #177 from DanielGoldfarb/master
change candle width defaults; add line width to algorithm
2 parents 49c5f7c + 51de01a commit b0c509f

File tree

7 files changed

+1236
-58
lines changed

7 files changed

+1236
-58
lines changed

examples/addplot.ipynb

Lines changed: 7 additions & 8 deletions
Large diffs are not rendered by default.

examples/panels.ipynb

Lines changed: 9 additions & 10 deletions
Large diffs are not rendered by default.

examples/scratch_pad/issues/issue171_widths.ipynb

Lines changed: 1161 additions & 0 deletions
Large diffs are not rendered by default.

examples/widths.ipynb

Lines changed: 35 additions & 29 deletions
Large diffs are not rendered by default.

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (0, 12, 5, 'alpha', 2)
2+
version_info = (0, 12, 5, 'alpha', 3)
33

44
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
55

src/mplfinance/_widths.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ def _get_widths_df():
1010
and observing which numbers gave the "best" appearance.
1111
'''
1212
numpoints = [n for n in range(30,241,30)]
13-
#volume_width = (0.95, 0.90, 0.85, 0.80, 0.75, 0.70, 0.65, 0.60 )
14-
#volume_width = (0.95, 0.925, 0.90, 0.875, 0.85, 0.825, 0.80, 0.775 )
1513
volume_width = (0.98, 0.96, 0.95, 0.925, 0.9, 0.9, 0.875, 0.825 )
1614
volume_linewidth = tuple([0.65]*8)
17-
candle_width = (0.65, 0.575, 0.50, 0.425, 0.350, 0.312, 0.312, 0.321)
18-
candle_linewidth = (1.00, 0.875, 0.75, 0.625, 0.500, 0.438, 0.438, 0.438)
15+
candle_width = (0.65, 0.575, 0.50, 0.445, 0.435, 0.425, 0.420, 0.415)
16+
candle_linewidth = (1.00, 0.875, 0.75, 0.625, 0.500, 0.438, 0.435, 0.435)
1917
ohlc_tickwidth = tuple([0.35]*8)
2018
ohlc_linewidth = (1.50, 1.175, 0.85, 0.525, 0.525, 0.525, 0.525, 0.525)
19+
line_width = (2.00, 1.600, 1.15, 0.720, 0.715, 0.710, 0.705, 0.700)
2120
widths = {}
2221
widths['vw'] = volume_width
2322
widths['vlw'] = volume_linewidth
2423
widths['cw'] = candle_width
2524
widths['clw'] = candle_linewidth
2625
widths['ow'] = ohlc_tickwidth
2726
widths['olw'] = ohlc_linewidth
27+
widths['lw'] = line_width
2828
return pd.DataFrame(widths,index=numpoints)
2929

3030
_widths = _get_widths_df()
@@ -39,6 +39,9 @@ def _valid_scale_width_kwargs():
3939

4040
'candle' : { 'Default' : None,
4141
'Validator' : lambda value: isinstance(value,(float,int)) },
42+
43+
'lines' : { 'Default' : None,
44+
'Validator' : lambda value: isinstance(value,(float,int)) },
4245
}
4346
_validate_vkwargs_dict(vkwargs)
4447
return vkwargs
@@ -63,6 +66,9 @@ def _valid_update_width_kwargs():
6366

6467
'candle_linewidth' : { 'Default' : None,
6568
'Validator' : lambda value: isinstance(value,(float,int)) },
69+
70+
'line_width' : { 'Default' : None,
71+
'Validator' : lambda value: isinstance(value,(float,int)) },
6672
}
6773
_validate_vkwargs_dict(vkwargs)
6874
return vkwargs
@@ -91,6 +97,7 @@ def _determine_width_config( xdates, config ):
9197
width_config['ohlc_linewidth' ] = None
9298
width_config['candle_width' ] = avg_dist_between_points / 2.0
9399
width_config['candle_linewidth'] = None
100+
width_config['line_width' ] = None
94101

95102
else: # config['width_adjuster_version'] == 'v1'
96103

@@ -100,16 +107,19 @@ def _determine_width_config( xdates, config ):
100107
width_config['ohlc_linewidth' ] = _dfinterpolate(_widths,datalen,'olw')
101108
width_config['candle_width' ] = _dfinterpolate(_widths,datalen,'cw' ) * adjust
102109
width_config['candle_linewidth'] = _dfinterpolate(_widths,datalen,'clw')
110+
width_config['line_width' ] = _dfinterpolate(_widths,datalen,'lw')
103111

104112
if config['scale_width_adjustment'] is not None:
105113

106114
scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs())
107115
if scale['volume'] is not None:
108-
width_config['volume_width'] *= scale['volume']
116+
width_config['volume_width'] *= scale['volume']
109117
if scale['ohlc'] is not None:
110118
width_config['ohlc_ticksize'] *= scale['ohlc']
111119
if scale['candle'] is not None:
112-
width_config['candle_width'] *= scale['candle']
120+
width_config['candle_width'] *= scale['candle']
121+
if scale['lines'] is not None:
122+
width_config['line_width'] *= scale['lines']
113123

114124

115125
if config['update_width_config'] is not None:

src/mplfinance/plotting.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def plot( data, **kwargs ):
306306

307307
collections = None
308308
if ptype == 'line':
309-
axA1.plot(xdates, closes, color=config['linecolor'])
309+
lw = config['_width_config']['line_width']
310+
axA1.plot(xdates, closes, color=config['linecolor'], linewidth=lw)
310311
else:
311312
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)
312313

@@ -333,16 +334,18 @@ def plot( data, **kwargs ):
333334

334335
# Get rcParams['lines.linewidth'] and scale it
335336
# according to the deinsity of data??
336-
337+
337338
for mav in mavgs:
338339
if ptype in VALID_PMOVE_TYPES:
339340
mavprices = pd.Series(brick_values).rolling(mav).mean().values
340341
else:
341342
mavprices = pd.Series(closes).rolling(mav).mean().values
343+
344+
lw = config['_width_config']['line_width']
342345
if mavc:
343-
axA1.plot(xdates, mavprices, color=next(mavc))
346+
axA1.plot(xdates, mavprices, linewidth=lw, color=next(mavc))
344347
else:
345-
axA1.plot(xdates, mavprices)
348+
axA1.plot(xdates, mavprices, linewidth=lw)
346349

347350
avg_dist_between_points = (xdates[-1] - xdates[0]) / float(len(xdates))
348351
if not config['tight_layout']:

0 commit comments

Comments
 (0)