Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fed025

Browse files
committed
fixed high/low for adjustment factor
svn path=/trunk/matplotlib/; revision=6989
1 parent 4ea4b96 commit 3fed025

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

examples/pylab_examples/finance_work2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def moving_average(x, n, type='simple'):
6363

6464
weights /= weights.sum()
6565

66+
6667
a = np.convolve(x, weights, mode='full')[:len(x)]
6768
a[:n] = a[n]
6869
return a
@@ -146,11 +147,15 @@ def moving_average_convergence(x, nslow=26, nfast=12):
146147
ax1.set_title('%s daily'%ticker)
147148

148149
### plot the price and volume data
150+
dx = r.adj_close - r.close
151+
low = r.low + dx
152+
high = r.high + dx
153+
149154
deltas = np.zeros_like(prices)
150155
deltas[1:] = np.diff(prices)
151156
up = deltas>0
152-
ax2.vlines(r.date[up], r.low[up], r.high[up], color='black', label='_nolegend_')
153-
ax2.vlines(r.date[~up], r.low[~up], r.high[~up], color='black', label='_nolegend_')
157+
ax2.vlines(r.date[up], low[up], high[up], color='black', label='_nolegend_')
158+
ax2.vlines(r.date[~up], low[~up], high[~up], color='black', label='_nolegend_')
154159
ma20 = moving_average(prices, 20, type='simple')
155160
ma200 = moving_average(prices, 200, type='simple')
156161

@@ -207,6 +212,7 @@ def moving_average_convergence(x, nslow=26, nfast=12):
207212

208213
ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
209214

215+
210216
class PriceFormatter(mticker.FormatStrFormatter):
211217
'suppress the lowest tick label to prevent overlap'
212218
def __call__(self, x, pos=None):
@@ -216,6 +222,7 @@ def __call__(self, x, pos=None):
216222
return mticker.FormatStrFormatter.__call__(self, x, pos=None)
217223

218224
ax2.yaxis.set_major_formatter(PriceFormatter('%d'))
225+
219226
plt.show()
220227

221228

0 commit comments

Comments
 (0)