in tensorwatch/mpl/bar_plot.py [0:0]
def _show_stream_items(self, stream_vis, stream_items):
"""Paint the given stream_items in to visualizer. If visualizer is dirty then return False else True.
"""
vals = self._extract_vals(stream_items)
if not len(vals):
return True
if not self.is_3d:
existing_len = len(stream_vis.series)
for i,val in enumerate(vals):
t = BarPlot._val2tuple(val, i+existing_len)
stream_vis.series[t[0]] = t # merge x with previous items
x, y, labels = [t[0] for t in stream_vis.series.values()], \
[t[1] for t in stream_vis.series.values()], \
[t[4] for t in stream_vis.series.values()]
self.clear_artists(stream_vis) # remove previous bars
bar_container = stream_vis.ax.bar(x, y,
width=stream_vis.bar_width,
tick_label = labels if any(l is not None for l in labels) else None,
color=stream_vis.color, edgecolor=stream_vis.edge_color,
alpha=stream_vis.opacity, linewidth=stream_vis.linewidth)
else:
for i,val in enumerate(vals):
t = BarPlot._val2tuple(val, None) # we should not use i paameter as 3d expects x,y,z
z = t[2]
if z not in stream_vis.series:
stream_vis.series[z] = []
stream_vis.series[t[2]] += [t] # merge z with previous items
# sort by z so we have consistent colors
ts = sorted(stream_vis.series.items(), key=lambda g: g[0])
for zi, (z, tg) in enumerate(ts):
x, y, labels = [t[0] for t in tg], \
[t[1] for t in tg], \
[t[4] for t in tg]
colors = stream_vis.color or stream_vis.cmap.colors
color = colors[zi % len(colors)]
self.clear_artists(stream_vis) # remove previous bars
bar_container = stream_vis.ax.bar(x, y, zs=z, zdir='y',
width=stream_vis.bar_width,
tick_label = labels if any(l is not None for l in labels) else None,
color=color,
edgecolor=stream_vis.edge_color,
alpha=stream_vis.opacity or 0.8, linewidth=stream_vis.linewidth)
stream_vis.bars_artists = bar_container.patches
#stream_vis.ax.relim()
#stream_vis.ax.autoscale_view()
return False