fossasia / visdom

A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.
Apache License 2.0
9.99k stars 1.14k forks source link

Fix Plotly Flicker on Quick Updates #904

Closed da-h closed 1 year ago

da-h commented 1 year ago

Description

Quick redraws of Plots tends to flickering (see example below). This PR fixes this by using the optimized Plotly.react instead of Plotly.newPlot for each redraw.

Motivation and Context

The bug has been spotted in #903. Edit: While this fix does improve the flickering, it may still occur. I suggest to still apply this more stable visualization and check alternative ideas in a future-PR.

How Has This Been Tested?

As suggested in #903, the flickering is best visible for heatmap plots. The following code-snippet reproduces the error.

def plot_surface_append_many(viz, env, withnames=False):
    win = plot_surface_basic(viz, env, withnames)
    viz.heatmap(
        X=np.outer(np.arange(6, 9), np.arange(1, 11)),
        win=win,
        update="appendRow",
        opts=dict(rownames=["y6", "y7", "y8"] if withnames else None),
        env=env,
    )
    import time

    for i in range(100):
        viz.heatmap(
            X=np.outer(np.arange(1, 9), np.arange(11, 14)),
            win=win,
            update="appendColumn",
            opts=dict(
                columnnames=["c1", "c2", "c3"] if withnames else None,
                colormap="Rainbow",
            ),
            env=env,
        )
        time.sleep(0.1)
Without this Fix With this Fix

Types of changes

Checklist:

da-h commented 1 year ago

Update: As mentioned in #904, flickering may still occur occasionally, but less frequently. Possibly https://github.com/plotly/react-plotly.js is a more robust solution?

I still suggest to merge this in, as it should provide a smoother although not perfect experience, yet.