Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change tqdm's bar size

Tags:

python

tqdm

I'm using tqdm's progress bar, and I'd like to shorten the bar itself by using an argument to indicate how many progress ticks the bar should have

So instead of this

Training (16): 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊| 983/984 [00:04<00:00, 242.42it/s, loss=0.0598]

I would get something like this

Training (16): 100%|█████████████| 983/984 [00:04<00:00, 242.42it/s, loss=0.0598]

I've explored the bar_format argument in tqdm's constructor, but couldn't figure out how to change it's size.

like image 605
bluesummers Avatar asked Jan 25 '19 09:01

bluesummers


1 Answers

The relevant formatting code is: {bar:10} -- if you want 10 characters of progress bar. In full, you would use it like this:

tqdm(iterator, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}')

or

tqdm(iterator, bar_format='{desc:<5.5}{percentage:3.0f}%|{bar:10}{r_bar}')

See also: https://github.com/tqdm/tqdm/issues/585

like image 164
Yaakov Belch Avatar answered Sep 22 '22 04:09

Yaakov Belch