def plot(self, widget, width = 0.6, colorup = 'r', colordown='g', lc='k', alpha=1):
"""docstring for plot"""
delta = self.width/2.
barVerts = [ ( (i-delta, open), (i-delta, close), (i+delta, close), (i+delta, open) ) for i, open, close in zip(xrange(len(self.data)), self.data.open, self.data.close) if open != -1 and close!=-1 ]
rangeSegments = [ ((i, low), (i, high)) for i, low, high in zip(xrange(len(self.data)), self.data.low, self.data.high) if low != -1 ]
r,g,b = colorConverter.to_rgb(self.colorup)
colorup = r,g,b,self.alpha
r,g,b = colorConverter.to_rgb(self.colordown)
colordown = r,g,b,self.alpha
colord = { True : colorup,
False : colordown,
}
colors = [colord[open<close] for open, close in zip(self.data.open, self.data.close) if open!=-1 and close !=-1]
assert(len(barVerts)==len(rangeSegments))
useAA = 0, # use tuple here
lw = 0.5, # and here
r,g,b = colorConverter.to_rgb(self.lc)
linecolor = r,g,b,self.alpha
lineCollection = LineCollection(rangeSegments,
colors = ( linecolor, ),
linewidths = lw,
antialiaseds = useAA,
zorder = 0,
)
barCollection = PolyCollection(barVerts,
facecolors = colors,
edgecolors = colors,
antialiaseds = useAA,
linewidths = lw,
zorder = 1,
)
#minx, maxx = 0, len(rangeSegments)
#miny = min([low for low in self.data.low if low !=-1])
#maxy = max([high for high in self.data.high if high != -1])
#corners = (minx, miny), (maxx, maxy)
#ax.update_datalim(corners)
widget.autoscale_view()
# add these last
widget.add_collection(barCollection)
widget.add_collection(lineCollection)
#ax.plot(self.data.close, color = 'y')
#lineCollection, barCollection = None, None
return lineCollection, barCollection
评论列表
文章目录