in tensorwatch/mpl/line_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 # not dirty
line = stream_vis.ax.get_lines()[-1]
if not self.is_3d:
xdata, ydata = line.get_data()
zdata = []
else:
xdata, ydata, zdata = line._verts3d # in future use get_data_3d(), these are numpy arrays
xdata, ydata, zdata = list(xdata), list(ydata), list(zdata)
anndata, txtdata, clrdata = [], [], []
lows, highs = [], [] # confidence interval
unpacker = lambda a0=None,a1=None,a2=None,a3=None,a4=None,a5=None,a6=None,a7=None,*_:\
(a0,a1,a2,a3,a4,a5,a6,a7)
# add each value in trace data
# each value is of the form:
# 2D graphs:
# y
# x [, y [,low, [, high [,annotation [, text [, color]]]]]]
# y
# x [, y [, z, [,low, [, high [annotation [, text [, color]]]]]
for val in vals:
# set defaults
x, y, z = len(xdata), None, None
low, high = None, None
ann, txt, clr = None, None, None
# if val turns out to be array-like, extract x,y
val_l = utils.is_scaler_array(val)
if val_l >= 0:
if self.is_3d:
x, y, z, low, high, ann, txt, clr = unpacker(*val)
else:
x, y, low, high, ann, txt, clr, _ = unpacker(*val)
elif isinstance(val, PointData):
x, y, z, low, high, ann, txt, clr = val.x, val.y, val.z, \
val.low, val.high, val.annotation, val.text, val.color
else:
y = val
if ann is not None:
ann = str(ann)
if txt is not None:
txt = str(txt)
xdata.append(x)
ydata.append(y)
zdata.append(z)
if low is not None:
lows.append(low)
if high is not None:
highs.append(high)
if txt is not None:
txtdata.append(txt)
if clr is not None:
clrdata.append(clr)
if ann: #TODO: yref should be y2 for different y axis
anndata.append(dict(x=x, y=y, xref='x', yref='y', text=ann, showarrow=False))
if not self.is_3d:
line.set_data(xdata, ydata)
else:
# in future use set_data_3d
line._verts3d = (xdata, ydata, zdata)
line.stale = True
if stream_vis.fill_between_col is not None:
stream_vis.fill_between_col.remove()
if len(lows) > 0 and len(highs) > 0:
stream_vis.ax.fill_between(xdata, highs, lows, color=stream_vis.color, alpha=0.2)
for ann in anndata:
stream_vis.xylabel_refs.append(stream_vis.ax.text( \
ann['x'], ann['y'], ann['text']))
stream_vis.ax.relim()
stream_vis.ax.autoscale_view(True,True,True)
return False # dirty