def plot(self): if self.ax is None: self.ax = pl.figure().add_subplot(111) ax = self.ax with update_ax(ax): sty = self.sty for k, v in self.baselines.items(): ax.axhline(v, label=k, **sty[k]) data = self.data for k, v in data.iteritems(): xs, ys = zip(*data[k]) if self.averaging: sty[k]['alpha'] = 0.5 [l] = ax.plot(xs, ys, label=k, **sty[k]) # show a dot in addition to the line if 0: s = sty[k].copy() s['lw'] = 0 s['c'] = l.get_color() ax.scatter(xs, ys, label=k, **s) if self.averaging: # TODO: averaging doesn't support irregular time steps. halflife = 10 _,yy = zip(*data[k]) ax.plot(xs, pandas.Series(yy).ewm(halflife=halflife).mean(), lw=2, c=l.get_color()) ax.set_title(self.name) if self.legend: ax.legend(loc=4)
def draw(self): ax = self.ax with update_ax(ax): sty = self.sty for k, v in self.baselines.items(): ax.axhline(v, label=k, **sty[k]) data = self.data for k, v in data.items(): xs, ys = np.array(data[k]).T if self.smoothing is not None: # mute the raw signal when we are smoothing. sty[k]['alpha'] = 0.5 [l] = ax.plot(xs, ys, label=k, **sty[k]) c = l.get_color() # show a dot in addition to the line if 0: s = sty[k].copy() s['lw'] = 0 s['c'] = c ax.scatter(xs, ys, label=k, **s) self.draw_smoothing(xs, ys, c=c) self.draw_bands(xs, ys, c=c) if self.xscale: ax.set_xscale(self.xscale) if self.yscale: ax.set_yscale(self.yscale) if self.name: ax.set_title(self.name) if self.legend: ax.legend(loc='best') self.draw_extra(ax) return self
def plot(self): if self.ax is None: self.ax = pl.figure().add_subplot(111) ax = self.ax with update_ax(ax): sty = self.sty for k, v in self.baselines.items(): ax.axhline(v, label=k, **sty[k]) data = self.data for k, v in data.iteritems(): xs, ys = zip(*data[k]) if self.averaging: sty[k]['alpha'] = 0.5 [l] = ax.plot(xs, ys, label=k, **sty[k]) # show a dot in addition to the line if 0: s = sty[k].copy() s['lw'] = 0 s['c'] = l.get_color() ax.scatter(xs, ys, label=k, **s) if self.averaging: # TODO: averaging doesn't support irregular time steps. halflife = 10 _, yy = zip(*data[k]) ax.plot(xs, pandas.Series(yy).ewm(halflife=halflife).mean(), lw=2, c=l.get_color()) ax.set_title(self.name) if self.legend: ax.legend(loc=4)
def plot(self): if self.ax is None: self.ax = pl.figure().add_subplot(111) ax = self.ax with update_ax(ax): sty = self.sty for k, v in self.baselines.items(): ax.axhline(v, label=k, **sty[k]) data = self.data for k, v in data.iteritems(): xs, ys = np.array(data[k]).T if self.averaging: sty[k]['alpha'] = 0.5 [l] = ax.plot(xs, ys, label=k, **sty[k]) # show a dot in addition to the line if 0: s = sty[k].copy() s['lw'] = 0 s['c'] = l.get_color() ax.scatter(xs, ys, label=k, **s) if self.averaging: s = pandas.Series(ys) if 0: halflife = 20 r = s.ewm(halflife=halflife) M = r.mean() s = r.std() U = M + 2 * s L = M - 2 * s else: window = min(len(ys), 10) r = s.rolling(window, min_periods=0) M = r.median() #U = r.max() #L = r.min() U = r.quantile(.9) L = r.quantile(.1) ax.plot(xs, M, lw=2, c=l.get_color()) ax.fill_between(xs, U, L, color=l.get_color(), alpha=0.25) if self.xscale: ax.set_xscale(self.xscale) if self.yscale: ax.set_yscale(self.yscale) if self.name: ax.set_title(self.name) if self.legend: ax.legend(loc='best')
def draw(self): if self.ax is None: self.ax = pl.figure().add_subplot(111) ax = self.ax with update_ax(ax): sty = self.sty for k, v in self.baselines.items(): ax.axhline(v, label=k, **sty[k]) data = self.data for k, v in data.items(): xs, ys = np.array(data[k]).T if self.smoothing is not None: sty[k]['alpha'] = 0.5 [l] = ax.plot(xs, ys, label=k, **sty[k]) # show a dot in addition to the line if 0: s = sty[k].copy() s['lw'] = 0 s['c'] = l.get_color() ax.scatter(xs, ys, label=k, **s) if self.smoothing is not None: s = pandas.Series(ys) if 0: halflife = 20 r = s.ewm(halflife=halflife) M = r.mean() s = r.std() U = M + 2*s L = M - 2*s else: window = min(len(ys), self.smoothing) r = s.rolling(window, min_periods=0) M = r.median() #U = r.max() #L = r.min() U = r.quantile(.9) L = r.quantile(.1) ax.plot(xs, M, lw=2, c=l.get_color()) ax.fill_between(xs, U, L, color=l.get_color(), alpha=0.25) if self.xscale: ax.set_xscale(self.xscale) if self.yscale: ax.set_yscale(self.yscale) if self.name: ax.set_title(self.name) if self.legend: ax.legend(loc='best')
def hinton(ax, W, gold, got, maxWeight=None, title=''): """Visualize pruning mask and parser output. Produces a image which is similar to an (upper-triangular) Hinton diagram. Size and color indicate pruning strength and whether hard decisions is keep/prune (white/black, respectively). Additional annotations * gold box -- unlabled span in "gold" standard tree * Parser output - green border: unlabeled item is correct. - red border: unlabeled is not correct. TODO: - How do I indicate errors in current parse? current visualization only shows which unlabeled spans are good? In many cases unlabeled recall is perfect, but labeled recall is quite low, e.g., 60%. """ N = W.shape[0] if ax is None: ax = pl.figure().add_subplot(111) def blob(x, y, area, c): """ Draws a square-shaped blob with the given area (< 1) at the given coordinates. """ hs = sqrt(area) / 2 xcorners = array([x - hs, x + hs, x + hs, x - hs]) ycorners = array([y - hs, y - hs, y + hs, y + hs]) ax.fill(xcorners, ycorners, c, edgecolor=c) with update_ax(ax): height, width = W.shape if maxWeight is None: maxWeight = np.max(np.abs(W)) / .5 ax.fill(array([1, width, width, 1]), array([0, 0, height, height]), 'gray') ax.axis('off') ax.axis('equal') for y in xrange(height): for x in xrange(y, width): _x = x+1 _y = y+1 w = W[y,x] if abs(x-y) > 1 and abs(x-y) != N: if (y, x) in got: if (y,x) in gold: c = 'green' else: c = 'red' blob(_x - 0.5, height - _y + 0.5, 0.85, c) if (y, x) in gold or abs(x-y) == 1 or abs(x-y) == N: blob(_x - 0.5, height - _y + 0.5, 0.70, 'yellow') if abs(x - y) in (0, 1, height): continue if w >= 0: blob(_x - 0.5, height - _y + 0.5, min(1, w / maxWeight), 'white') else: blob(_x - 0.5, height - _y + 0.5, min(1, -w / maxWeight), 'black') if title: ax.set_title(title)