Skip to content

Instantly share code, notes, and snippets.

@Cheneng
Created June 21, 2018 02:13
Show Gist options
  • Save Cheneng/9f66e994b16c07b43c6cbe8a3e3319cb to your computer and use it in GitHub Desktop.
Save Cheneng/9f66e994b16c07b43c6cbe8a3e3319cb to your computer and use it in GitHub Desktop.
draw multiple lines in visdom
def draw_line(vis, step, lines, names):
# draw multiple lines in one panel.
"""
:param vis: the object of the visdom.Visdom
:param step: the step of the line
:param lines: the lines tuple, (line1, line2, ...)
:param names: the names tuple, (name1, name2, ...)
:return: None
"""
if not len(lines) == len(names):
raise ValueError('The length of the input is not the same')
win_name = ''
for i in range(len(names)):
win_name += names[i]
if step == 0:
for line, name in zip(lines, names):
vis.line(X=torch.Tensor([step]),
Y=torch.Tensor([line]),
win=win_name,
name='%s' % name,
opts=dict(legend=[name])
)
else:
for line, name in zip(lines, names):
vis.updateTrace(X=torch.Tensor([step]),
Y=torch.Tensor([line]),
win=win_name,
name='%s' % name
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment