How to change tqdm's bar size

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


You need to pass a value for ncols. This defaults to the width of the terminal so if you want it to be less you have to say so.

From https://github.com/tqdm/tqdm

ncols : int, optional
The width of the entire output message. If specified, dynamically resizes the progressbar to stay within this bound. If unspecified, attempts to use environment width. The fallback is a meter width of 10 and no limit for the counter and statistics. If 0, will not print any meter (only stats).

Tags:

Python

Tqdm