2016-08-09 7 views
3

Wie implementiere ich einen Fortschrittsbalken in Jupyter-Notebook?Wie implementiere ich einen Fortschrittsbalken?

Ich habe dies getan:

count = 0 
max_count = 100 
bar_width = 40 
while count <= max_count: 
    time.sleep(.1) 
    b = bar_width * count/max_count 
    l = bar_width - b 
    print '\r' + u"\u2588" * b + '-' * l, 
    count += 1 

das ist toll, wenn ich Zugang zu einer Schleife haben, in dem aus Material zu drucken. Aber weiß irgendjemand etwas, das schlau ist, asynchron einen Fortschrittsbalken irgendeiner Art zu betreiben?

Antwort

5

Hier ist eine Lösung (nach this) ist.

from ipywidgets import FloatProgress 
from IPython.display import display 
import time 

max_count = 100 

f = FloatProgress(min=0, max=max_count) # instantiate the bar 
display(f) # display the bar 

count = 0 
while count <= max_count: 
    f.value += 1 # signal to increment the progress bar 
    time.sleep(.1) 
    count += 1 
2

Sie können versuchen tqdm. Beispielcode:

# pip install tqdm 
from tqdm import tqdm_notebook 

# works on any iterable, including cursors. 
# for iterables with len(), no need to specify 'total'. 
for rec in tqdm_notebook(positions_collection.find(), 
         total=positions_collection.count(), 
         desc="Processing records"): 
    # any code processing the elements in the iterable 
    len(rec.keys()) 

Demo: https://youtu.be/T0gmQDgPtzY

Verwandte Themen