Tqdm: Cannot redraw tqdm_notebook Hbox progress bar after calling clear_output(), only ascii shown

Created on 23 Sep 2019  Â·  3Comments  Â·  Source: tqdm/tqdm

  • [x] I have visited the [source website], and in particular
    read the [known issues]
  • [x] I have searched through the [issue tracker] for duplicates
  • [x] I have mentioned version numbers, operating system and
    environment, where applicable:
    python import tqdm, sys print(tqdm.__version__, sys.version, sys.platform) #4.36.1 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0] linux

When I clean the output of a cell during runtime with IPython.display.clear_output() and want to re-draw the tddm_notebook progress bar I only get an ascii representation instead of the HBox. I'm not sure if this is a bug or not possible by design. A simple example here:

%matplotlib inline
import time
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm_notebook

from IPython.display import display, clear_output, update_display

fig, ax = plt.subplots(1, 1)
style = ['bo', 'rs', 'gd']

progress_bar = tqdm_notebook(iterable=range(50), leave=True)

for ii in progress_bar:
    for jj in range(3):
        ax.plot(ii, np.random.randn(1), style[jj])

    clear_output(wait=True)
    display(fig)
    display(progress_bar)
    plt.pause(1)

This should display a plot and a progress bar which are both updated on every iteration. The figure is shown correctly, the progress bar just as ascii. Calling .display() or .refresh() on the tqdm_notebook progress bar has no effect.

invalid ⛔ questiodocs ‽ submodule-notebook 📓

Most helpful comment

According to this issue https://github.com/jupyter-widgets/ipywidgets/issues/1744
you can only erase your plot:

import time
import numpy as np
import matplotlib.pyplot as plt
from tqdm.auto import trange

from IPython import display
from ipywidgets import Output

out = Output()
display.display(out)
for i in trange(10):
    with out:
        plt.plot(np.random.randn(100))
        plt.show()
        display.clear_output(wait=True)
    time.sleep(1)

All 3 comments

think this is a jupyter thing. You get the same effect using e.g. matplotlib figures instead of tqdm progress bars.

The object still exists but you've cleared its display so can't see it.

happy to re-open if there's anything we can do.

According to this issue https://github.com/jupyter-widgets/ipywidgets/issues/1744
you can only erase your plot:

import time
import numpy as np
import matplotlib.pyplot as plt
from tqdm.auto import trange

from IPython import display
from ipywidgets import Output

out = Output()
display.display(out)
for i in trange(10):
    with out:
        plt.plot(np.random.randn(100))
        plt.show()
        display.clear_output(wait=True)
    time.sleep(1)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlumpe picture jlumpe  Â·  5Comments

anntzer picture anntzer  Â·  5Comments

casperdcl picture casperdcl  Â·  5Comments

ddkang picture ddkang  Â·  4Comments

techkang picture techkang  Â·  4Comments