tqdm 可以与绘图一起使用吗?

发布于 2025-01-11 20:45:15 字数 111 浏览 3 评论 0原文

首次使用 tqdm 用户。进度条开始移动,但随后什么也不做。我也得到了一些有趣的图形输出

First-time tqdm user. The progress bar starts to move but then does nothing. I'm getting some interesting graph output as well ???? I guess it isn't meant to be used with plots? Am I supposed to pre-empt the plot output with another time method?

categ = data.iloc[:,categorical_indexes]
fig, axes = plt.subplots(6, 3, figsize = (20, 20))
for i, col in enumerate(tqdm_notebook(categ, desc = 'Progress()')):
    column_values = data[col].value_counts()
    labels = column_values.index
    sizes = column_values.values
    axes[i//3, i%3].pie(sizes, labels = labels, colors = sns.color_palette("YlOrBr"), autopct = '%1.0f%%', startangle = 90)
    axes[i//3, i%3].axis('equal')
    axes[i//3, i%3].set_title(col)
plt.show()

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2025-01-18 20:45:15

categ 是一个长度为 103904 的 Iterable 吗?如果不是,这可能表明循环中的某些内容可能与您的预期不同。

你是如何导入tqdm的?看到 tqdm_notebook 让我觉得您可能正在使用一种已弃用/维护得不好的方式来使用 tqdm 中的进度条。

我通常在笔记本中使用 tqdm 的两种方式:

from tqdm.notebook import tqdm

# as progress bar where you manually update
pbar = tqdm(desc="x", total=10)  # total is optional
for i in range(10):
    pbar.update(1)
    continue
pbar.close()
# alternative: 'with tqdm(desc="x", total=10) as pbar:' + skip the 'pbar.close()'

# wrapped around the iterable
for i in tqdm(range(10), desc="y"):
    continue

我之前在简单循环中使用 tqdm 来创建绘图,到目前为止还没有出现问题。如果您的问题仍然存在,请查看 SO线程当程序中存在异步性或存在除系统控制台之外的文本输出连接时,解决 tqdm 潜在问题的解决方案。

Is categ an Iterable with a length of 103904? If not, this might be an indicator that something about the loop could be different from what you expect.

How did you import tqdm? Seeing tqdm_notebook makes me think you might be using a deprecated/not that well maintained way of using the progress bar in tqdm.

Two ways how I usually use tqdm in Notebooks:

from tqdm.notebook import tqdm

# as progress bar where you manually update
pbar = tqdm(desc="x", total=10)  # total is optional
for i in range(10):
    pbar.update(1)
    continue
pbar.close()
# alternative: 'with tqdm(desc="x", total=10) as pbar:' + skip the 'pbar.close()'

# wrapped around the iterable
for i in tqdm(range(10), desc="y"):
    continue

I used tqdm in simple loops for creating plots before and did not have problems so far. If your problem persists check out this SO-thread for solutions to potential problems with tqdm when there is asynchronousity in your program or there are text output connections other than the system console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文