| 72 | return wrapper |
| 73 | |
| 74 | class Candles(object): |
| 75 | def __init__(self, tracker, data, name='candle', width = 0.6, colorup = 'r', colordown='g', lc='k', alpha=1): |
| 76 | """ Represent the open, close as a bar line and high low range as a |
| 77 | vertical line. |
| 78 | |
| 79 | |
| 80 | ax : an Axes instance to plot to |
| 81 | width : the bar width in points |
| 82 | colorup : the color of the lines where close >= open |
| 83 | colordown : the color of the lines where close < open |
| 84 | alpha : bar transparency |
| 85 | |
| 86 | return value is lineCollection, barCollection |
| 87 | """ |
| 88 | #super(Candles, self).__init__(tracker, name) |
| 89 | self.set_yrange(data.low.values, data.high.values) |
| 90 | self.data = data |
| 91 | self.name = name |
| 92 | self.width = width |
| 93 | self.colorup = colorup |
| 94 | self.colordown = colordown |
| 95 | self.lc = lc |
| 96 | self.alpha = alpha |
| 97 | |
| 98 | # note this code assumes if any value open, close, low, high is |
| 99 | # missing they all are missing |
| 100 | @override_attributes |
| 101 | def plot(self, widget, width = 0.6, colorup = 'r', colordown='g', lc='k', alpha=1): |
| 102 | """docstring for plot""" |
| 103 | delta = self.width/2. |
| 104 | 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 ] |
| 105 | rangeSegments = [ ((i, low), (i, high)) for i, low, high in zip(xrange(len(self.data)), self.data.low, self.data.high) if low != -1 ] |
| 106 | r,g,b = colorConverter.to_rgb(self.colorup) |
| 107 | colorup = r,g,b,self.alpha |
| 108 | r,g,b = colorConverter.to_rgb(self.colordown) |
| 109 | colordown = r,g,b,self.alpha |
| 110 | colord = { True : colorup, |
| 111 | False : colordown, |
| 112 | } |
| 113 | colors = [colord[open<close] for open, close in zip(self.data.open, self.data.close) if open!=-1 and close !=-1] |
| 114 | assert(len(barVerts)==len(rangeSegments)) |
| 115 | useAA = 0, # use tuple here |
| 116 | lw = 0.5, # and here |
| 117 | r,g,b = colorConverter.to_rgb(self.lc) |
| 118 | linecolor = r,g,b,self.alpha |
| 119 | lineCollection = LineCollection(rangeSegments, |
| 120 | colors = ( linecolor, ), |
| 121 | linewidths = lw, |
| 122 | antialiaseds = useAA, |
| 123 | zorder = 0, |
| 124 | ) |
| 125 | |
| 126 | barCollection = PolyCollection(barVerts, |
| 127 | facecolors = colors, |
| 128 | edgecolors = colors, |
| 129 | antialiaseds = useAA, |
| 130 | linewidths = lw, |
| 131 | zorder = 1, |