Visdom: Feature Request

Created on 2 Jan 2018  路  6Comments  路  Source: fossasia/visdom

I'm not sure if this is already possible. Excuse me if it does.

Can I plot two live experiments in the same plot ? i.e. is there a way to make two scripts plot a line in the same plot ?

Most helpful comment

As long as the two experiments don't need to be aware of each other though this is definitely supported simply by using the same env and win inputs. As long as each plot uses a unique name they will be shown as separate lines on the same plot.
Two caveats
1) You'll need to use the legend opt and give it a unique value for experiment 1 and experiment 2.
2) Only the first experiment to create the window should use viz.line without using the update parameter. All subsequent calls should update the existing one. This can be implemented using viz.win_exists as such:

# Exp 1
if not viz.win_exists('expPlot'):
    viz.line(X=xData, Y=yData, win='expPlot', opts=dict(legend=['Experiment 1']))
else:
    viz.line(X=xData, Y=yData, win='expPlot', name='Experiment 1', update=True)


# Exp 2
if not viz.win_exists('expPlot'):
    viz.line(X=xData, Y=yData, win='expPlot', opts=dict(legend=['Experiment 2']))
else:
    viz.line(X=xData, Y=yData, win='expPlot', name='Experiment 2', update=True)

If you also want to update these over time by appending rather than replacing a line, you can use the update = 'append' feature to append new data to the plot for a given line:

viz.line(
    X=newXData, 
    Y=newYVals, 
    win='expPlot, 
    name='Experiment 2',
    update='append'
)

All 6 comments

You can have two different experiments push data to the same plot by having both experiments use the same values for env and win as input into vis.line, vis.scatter, etc.

The behavior you describe is somewhat tricky to implement right now though, because the Python client does not maintain state, so there is no way for experiment 2 to retrieve data pushed by experiment 1 (or vice versa). The server does maintain state (for instance, state is retrieved here), but I don't think it is currently exposed to the user via the client. So I think you'd have to add a special handler to the server that returns state, expose this handler by adding a function in the Python client, and use explicitly alter the state in your experimental code in a way that leads to the desired behavior.

As long as the two experiments don't need to be aware of each other though this is definitely supported simply by using the same env and win inputs. As long as each plot uses a unique name they will be shown as separate lines on the same plot.
Two caveats
1) You'll need to use the legend opt and give it a unique value for experiment 1 and experiment 2.
2) Only the first experiment to create the window should use viz.line without using the update parameter. All subsequent calls should update the existing one. This can be implemented using viz.win_exists as such:

# Exp 1
if not viz.win_exists('expPlot'):
    viz.line(X=xData, Y=yData, win='expPlot', opts=dict(legend=['Experiment 1']))
else:
    viz.line(X=xData, Y=yData, win='expPlot', name='Experiment 1', update=True)


# Exp 2
if not viz.win_exists('expPlot'):
    viz.line(X=xData, Y=yData, win='expPlot', opts=dict(legend=['Experiment 2']))
else:
    viz.line(X=xData, Y=yData, win='expPlot', name='Experiment 2', update=True)

If you also want to update these over time by appending rather than replacing a line, you can use the update = 'append' feature to append new data to the plot for a given line:

viz.line(
    X=newXData, 
    Y=newYVals, 
    win='expPlot, 
    name='Experiment 2',
    update='append'
)

Oh yeah... I forgot about the name option :)

Nice solution!

Uh okay, that's helpful. @lvdmaaten thanks for explaining the problem there and @JackUrb thanks for explaining.

Also on a side note, are the window ids logged somewhere ? I have begun running a long experiment and would like to get the window id so that I can add some other plots to it.

As of now they're only logged on close, though you can get around closing it by saving your environment, forking it, and then closing the window in the forked environment. The window id will be logged in the stdout of the server then and you can then return to the old environment.

Okay, I see. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IssamLaradji picture IssamLaradji  路  3Comments

cympfh picture cympfh  路  6Comments

sbaio picture sbaio  路  3Comments

shubhamjain0594 picture shubhamjain0594  路  3Comments

pedropgusmao picture pedropgusmao  路  3Comments