Skip to content

Commit

Permalink
Merge pull request matplotlib#177 from DanielGoldfarb/master
Browse files Browse the repository at this point in the history
change candle width defaults; add line width to algorithm
  • Loading branch information
DanielGoldfarb committed Jun 16, 2020
2 parents 49c5f7c + 51de01a commit b0c509f
Show file tree
Hide file tree
Showing 7 changed files with 1,236 additions and 58 deletions.
15 changes: 7 additions & 8 deletions examples/addplot.ipynb

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions examples/panels.ipynb

Large diffs are not rendered by default.

1,161 changes: 1,161 additions & 0 deletions examples/scratch_pad/issues/issue171_widths.ipynb

Large diffs are not rendered by default.

64 changes: 35 additions & 29 deletions examples/widths.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mplfinance/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

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

Expand Down
22 changes: 16 additions & 6 deletions src/mplfinance/_widths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ def _get_widths_df():
and observing which numbers gave the "best" appearance.
'''
numpoints = [n for n in range(30,241,30)]
#volume_width = (0.95, 0.90, 0.85, 0.80, 0.75, 0.70, 0.65, 0.60 )
#volume_width = (0.95, 0.925, 0.90, 0.875, 0.85, 0.825, 0.80, 0.775 )
volume_width = (0.98, 0.96, 0.95, 0.925, 0.9, 0.9, 0.875, 0.825 )
volume_linewidth = tuple([0.65]*8)
candle_width = (0.65, 0.575, 0.50, 0.425, 0.350, 0.312, 0.312, 0.321)
candle_linewidth = (1.00, 0.875, 0.75, 0.625, 0.500, 0.438, 0.438, 0.438)
candle_width = (0.65, 0.575, 0.50, 0.445, 0.435, 0.425, 0.420, 0.415)
candle_linewidth = (1.00, 0.875, 0.75, 0.625, 0.500, 0.438, 0.435, 0.435)
ohlc_tickwidth = tuple([0.35]*8)
ohlc_linewidth = (1.50, 1.175, 0.85, 0.525, 0.525, 0.525, 0.525, 0.525)
line_width = (2.00, 1.600, 1.15, 0.720, 0.715, 0.710, 0.705, 0.700)
widths = {}
widths['vw'] = volume_width
widths['vlw'] = volume_linewidth
widths['cw'] = candle_width
widths['clw'] = candle_linewidth
widths['ow'] = ohlc_tickwidth
widths['olw'] = ohlc_linewidth
widths['lw'] = line_width
return pd.DataFrame(widths,index=numpoints)

_widths = _get_widths_df()
Expand All @@ -39,6 +39,9 @@ def _valid_scale_width_kwargs():

'candle' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,(float,int)) },

'lines' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,(float,int)) },
}
_validate_vkwargs_dict(vkwargs)
return vkwargs
Expand All @@ -63,6 +66,9 @@ def _valid_update_width_kwargs():

'candle_linewidth' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,(float,int)) },

'line_width' : { 'Default' : None,
'Validator' : lambda value: isinstance(value,(float,int)) },
}
_validate_vkwargs_dict(vkwargs)
return vkwargs
Expand Down Expand Up @@ -91,6 +97,7 @@ def _determine_width_config( xdates, config ):
width_config['ohlc_linewidth' ] = None
width_config['candle_width' ] = avg_dist_between_points / 2.0
width_config['candle_linewidth'] = None
width_config['line_width' ] = None

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

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

if config['scale_width_adjustment'] is not None:

scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs())
if scale['volume'] is not None:
width_config['volume_width'] *= scale['volume']
width_config['volume_width'] *= scale['volume']
if scale['ohlc'] is not None:
width_config['ohlc_ticksize'] *= scale['ohlc']
if scale['candle'] is not None:
width_config['candle_width'] *= scale['candle']
width_config['candle_width'] *= scale['candle']
if scale['lines'] is not None:
width_config['line_width'] *= scale['lines']


if config['update_width_config'] is not None:
Expand Down
11 changes: 7 additions & 4 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def plot( data, **kwargs ):

collections = None
if ptype == 'line':
axA1.plot(xdates, closes, color=config['linecolor'])
lw = config['_width_config']['line_width']
axA1.plot(xdates, closes, color=config['linecolor'], linewidth=lw)
else:
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)

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

# Get rcParams['lines.linewidth'] and scale it
# according to the deinsity of data??

for mav in mavgs:
if ptype in VALID_PMOVE_TYPES:
mavprices = pd.Series(brick_values).rolling(mav).mean().values
else:
mavprices = pd.Series(closes).rolling(mav).mean().values

lw = config['_width_config']['line_width']
if mavc:
axA1.plot(xdates, mavprices, color=next(mavc))
axA1.plot(xdates, mavprices, linewidth=lw, color=next(mavc))
else:
axA1.plot(xdates, mavprices)
axA1.plot(xdates, mavprices, linewidth=lw)

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

0 comments on commit b0c509f

Please sign in to comment.