Skip to content

Commit

Permalink
specify xtick locations for pnf
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGoldfarb committed Dec 8, 2022
1 parent d92bacc commit 9003a9c
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 563 deletions.
742 changes: 181 additions & 561 deletions examples/scratch_pad/issues/issue568_pnf_calcs.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/mplfinance/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,8 +1573,9 @@ def _construct_pnf_scatter(ax,ptype,dates,xdates,opens,highs,lows,closes,volumes
lo = min(yvals)
xlen = int(round((hi-lo)/box_size,0)+2) # +2 empirical kludge
pad = (xlen-xvals[-1]) * pointnfig_params['scale_right_padding']
print('hi,lo,xlen,xvals[-1],pad=',hi,lo,xlen,xvals[-1],pad)
print('ylim_top,ylim_bot=',ylim_top,ylim_bot)
pad = max(0,pad) # less than zero not allowed
#print('hi,lo,xlen,xvals[-1],pad=',hi,lo,xlen,xvals[-1],pad)
#print('ylim_top,ylim_bot=',ylim_top,ylim_bot)

xdates = np.arange(len(pnfd)+int(pad))
pnf_volumes = pnf_volumes + [float('nan')]*int(pad)
Expand Down
6 changes: 6 additions & 0 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ def plot( data, **kwargs ):
pnf_os = list(pnf_results['pnf_df'].OBox.values)
tick_vals = sorted( set(pnf_xs + pnf_os) )
axA1.set_yticks(tick_vals)
skip = int( round(len(xdates)/10.0, 0) )
skip = max(1,skip) # must be at least 1
tick_vals = [t for t in range(0-skip,len(xdates)+1,skip)]
#print('len(xdates)=',len(xdates),'len(pnf_mdates)=',len(pnf_mdates))
#print('skip=',skip,'\nxdates=',xdates,'\npnf_dates=',[str(d.date()) for d in mdates.num2date(pnf_mdates)])
axA1.set_xticks(tick_vals)

ysd = config['yscale']
if isinstance(ysd,dict):
Expand Down

0 comments on commit 9003a9c

Please sign in to comment.