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

Skip to content

Commit fd88c28

Browse files
committed
some cleanups to the volume overlay
svn path=/trunk/matplotlib/; revision=6992
1 parent afc464c commit fd88c28

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

examples/pylab_examples/finance_work2.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def relative_strength(prices, n=14):
8080
up = seed[seed>=0].sum()/n
8181
down = -seed[seed<0].sum()/n
8282
rs = up/down
83-
rsi = np.zeros_like(r.adj_close)
83+
rsi = np.zeros_like(prices)
8484
rsi[:n] = 100. - 100./(1.+rs)
8585

8686
for i in range(n, len(prices)):
@@ -129,6 +129,8 @@ def moving_average_convergence(x, nslow=26, nfast=12):
129129
ax2t = ax2.twinx()
130130
ax3 = fig.add_axes(rect3, axisbg=axescolor, sharex=ax1)
131131

132+
133+
132134
### plot the relative strength indicator
133135
prices = r.adj_close
134136
rsi = relative_strength(prices)
@@ -176,13 +178,13 @@ def moving_average_convergence(x, nslow=26, nfast=12):
176178
leg = ax2.legend(loc='center left', shadow=True, fancybox=True, prop=props)
177179
leg.get_frame().set_alpha(0.5)
178180

179-
vmax = r.volume.max()/1e6
180-
poly = ax2t.fill_between(r.date, r.volume/1e6, 0, facecolor=fillcolor, label='Volume')
181+
182+
volume = (r.close*r.volume)/1e6 # dollar volume in millions
183+
vmax = volume.max()
184+
poly = ax2t.fill_between(r.date, volume, 0, facecolor=fillcolor, label='Volume')
181185
ax2t.set_ylim(0, 5*vmax)
182-
ymax = np.int(vmax)
183-
yticks = [vmax/2., vmax]
184-
ax2t.set_yticks(yticks)
185-
ax2t.set_yticklabels(['%d M'%val for val in yticks])
186+
ax2t.set_yticks([])
187+
186188

187189
### compute the MACD indicator
188190
fillcolor = 'darkslategrey'
@@ -220,7 +222,6 @@ def __call__(self, x, pos=None):
220222
return ''
221223
else:
222224
return mticker.FormatStrFormatter.__call__(self, x, pos=None)
223-
224225
ax2.yaxis.set_major_formatter(PriceFormatter('%d'))
225226

226227
plt.show()

0 commit comments

Comments
 (0)