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.
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)
Most helpful comment
According to this issue https://github.com/jupyter-widgets/ipywidgets/issues/1744
you can only erase your plot: