ijulia印刷每一行的进度栏

发布于 2025-02-11 00:03:27 字数 650 浏览 2 评论 0 原文

我目前正在学习朱莉娅(Julia),并且一直在Jupyter笔记本电脑环境中练习。但是,ProgressBar软件包(类似于Python中的TQDM)已更新每条新行,而不是在同一行上更新(图片附加)。有什么方法可以解决此问题吗?谢谢。

Update :这是我写的完整功能。

function spike_rate(raw_dat, width)

    N = size(raw_dat)[1]
    domain = collect(1:N);
    spike_rat = zeros(N);

    for i in ProgressBar(1:N)
        dx = i .- domain;
        window = gaussian.(dx, width);
        spike_rat[i] = sum(window .* raw_dat) ./ width;
    end

    return spike_rat;

end

I am currently learning Julia and have been practicing in the Jupyter notebook environment. However, the ProgressBar package (similar to TQDM in python) is updated every new line instead of updating on the same line (picture attached). Is there any way to fix this? Thanks.

UPDATE : Here is the full function that I wrote.

function spike_rate(raw_dat, width)

    N = size(raw_dat)[1]
    domain = collect(1:N);
    spike_rat = zeros(N);

    for i in ProgressBar(1:N)
        dx = i .- domain;
        window = gaussian.(dx, width);
        spike_rat[i] = sum(window .* raw_dat) ./ width;
    end

    return spike_rat;

end

enter image description here

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

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

发布评论

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

评论(2

洛阳烟雨空心柳 2025-02-18 00:03:28

有一种方法,据我所知,包装模块是这样做的:

] up

您可以分享一些代码吗?
例如,在哪里定义写在控制台上的内容。
一个猜测是

print("text and progressbar")

,而不是

println("text and progressbar")

可以帮助您,因为 println()始终创建一个新行,而 print()应该只覆盖当前行。

There is a way, the package module does that as far as I know when you do:

] up

Could you share a little of your code?
For example, where you define what is written to the console.
One guess is that

print("text and progressbar")

instead of

println("text and progressbar")

could help, because println() always creates a new line, while print() should just overwrite you current line.

嗳卜坏 2025-02-18 00:03:27

这似乎是已知 esgease 不幸的是。目前尚不清楚如何使这些进度栏不再正常,而是维护者的评论说TQDM使用“自定义iPywidget”来为Python库做这项工作,但尚未为Julia套件实施。

要扩展 @Zitzero提及的] UP ,该调用 pkg.update()也打印了进度栏 - 因此建议是使用该机制 pkg 用于它。 pkg 具有一个内部模块,称为 miniprogressbars 可以处理此输出。


edit :蒂姆·霍尔(Tim Holy's) progressmeter package package 看起来很好,并且是且是良好的,并且是一个比依靠没有文档的内部非代码> pkg 子模块要好得多。因此,我建议下面的进度表。

读书文件提到 Miniprogressbar 。因此,使用 progressmeter ,并将进度输出与其他相关输出分开​​为不同的单元格,似乎是最佳选择。


(不推荐)

using Pkg.MiniProgressBars

bar = MiniProgressBar(; indent=2, header = "Progress", color = Base.info_color(),
                              percentage=false, always_reprint=true)
bar.max = 100

# start_progress(stdout, bar)
for i in 1:100
    sleep(0.05) # replace this with your code
    # print_progress_bottom(stdout)
    bar.current = i 
    show_progress(stdout, bar)
end
# end_progress(stdout, bar)

这是基于 pkg 使用它的方法src/operations.jl#l988“ rel =“ nofollow noreferrer”>来自此文件。评论的线(使用 start_progress print_progress_bottom end_progress )在 pkg 中的原始用法中,但是目前尚不清楚他们做什么,在这里他们似乎只是弄乱了输出 - 也许我错误地使用了它们,或者jupyter笔记本仅支持 miniprogressbars 使用的ANSI代码的子集。

This seems to be a known issue with ProgressBars.jl, unfortunately. It's not clear what changed to make these progress bars not work properly anymore, but the maintainer's comment says that tqdm uses "a custom ipywidget" to make this work for the Python library, and that hasn't been implemented for the Julia package yet.

To expand on @Zitzero's mention of ] up, that calls Pkg.update() which also prints a progress bar - so the suggestion is to use the mechanism Pkg uses for it. Pkg has an internal module called MiniProgressBars which handles this output.


Edit: Tim Holy's ProgressMeter package seems well-maintained, and is a much better option than relying on an internal non-exported Pkg submodule with no docs. So I'd recommend ProgressMeter over the below.

The Readme mentions a caveat regarding printing additional information with the progress bar when in Jupyter, which likely applies to MiniProgressBar as well. So, using ProgressMeter, and separating the progress output vs other relevant output to different cells, seems like the best option.


(not recommended)

using Pkg.MiniProgressBars

bar = MiniProgressBar(; indent=2, header = "Progress", color = Base.info_color(),
                              percentage=false, always_reprint=true)
bar.max = 100

# start_progress(stdout, bar)
for i in 1:100
    sleep(0.05) # replace this with your code
    # print_progress_bottom(stdout)
    bar.current = i 
    show_progress(stdout, bar)
end
# end_progress(stdout, bar)

This is based on how Pkg uses it, from this file. The commented out lines (with start_progress, print_progress_bottom, and end_progress) are in the original usage in Pkg, but it's not clear what they do and here they just seem to mess up the output - maybe I'm using them wrongly, or maybe Jupyter notebooks only support a subset of the ANSI codes that MiniProgressBars uses.

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