from visdom import Visdom import random import numpy as np def InitVisdom(): viz = Visdom() assert viz.check_connection() viz.close() class Line(): def __init__(self,name,size): super(Line, self).__init__() self.name=name self.size=size def __init__(self): super(Line, self).__init__() self.name=str(random.random()) self.size=0 def __init__(self,name): super(Line, self).__init__() self.name=name self.size=0 class LineWin(): def __init__(self): super(LineWin, self).__init__() self.viz = Visdom() self.name = str(random.random()) self.win = self.viz.line( X=np.array([0]), Y=np.array([0]), name=self.name ) self.data = np.array([]) def AppendLine(self,y): if not isinstance(y,list): y = [y] linename = str(random.random()) self.viz.line( X=np.array(range(len(y))), Y=np.array(y), opts=dict(markercolor=np.array([50]), markersymbol='dot',), win=self.win, update="new", name=linename, ) return Line(linename,len(y)) def AppendData(self,line, y): if not isinstance(y,list): y = [y] self.viz.line( X=np.array(range(line.size, line.size+len(y))), Y=np.array(y), win=self.win, update="append", name=line.name ) line.size = line.size + len(y)