def add_bars(self, colorup='g', colordown='r', alpha=0.5, width=1):
r,g,b = colorConverter.to_rgb(colorup)
colorup = r,g,b,alpha
r,g,b = colorConverter.to_rgb(colordown)
colordown = r,g,b,alpha
colord = {True: colorup, False: colordown}
colors = [colord[open<close] for open, close in zip(self.opens, self.closes)]
delta = width/2.0
bars = [((x-delta, 0), (x-delta, y), (x+delta, y), (x+delta, 0))
for x, y in zip(self.dates, self.volumes)]
barCollection = PolyCollection(bars, facecolors = colors)
#self.ax.step(self.dates, self.volumes)
#self.ax.add_collection(barCollection)
#self.ax.bar(self.dates, self.volumes)
#self.ax.plot(self.dates, self.volumes)
self.ax.fill_between(self.dates, self.volumes, alpha=0.5)
xmin, xmax = self.ax.get_xlim()
ys = [y for x, y in zip(self.dates, self.volumes) if xmin<=x<=xmax]
if ys:
self.ax.set_ylim([0, max(ys)*10])
for tick in self.ax.get_yticklabels():
tick.set_visible(False)
评论列表
文章目录