gpt4 book ai didi

python - 如何在 ipython 笔记本中重新加载图像?

转载 作者:太空狗 更新时间:2023-10-29 21:45:40 26 4
gpt4 key购买 nike

在我的笔记本中,我可以像这样在同一文件夹中以 Markdown 显示图像:

<img src="files/adaptive_filter.png" alt="Schema of adaptive filter" height="100"> 

如果我在 src 中使用没有 files/ 的代码,它将不起作用。

现在我更改了图像,ipython 笔记本仍然显示原始图像。我尝试从代码中删除它并重新启动笔记本,但没有帮助。

我该怎么办?图片是否存储在某处?

提前致谢。

最佳答案

我也遇到了这个问题,当时我使用自己的类来输出一些 python 图并将它们嵌入到 IPython 笔记本中。解决此问题的一种 hack 方法是在图像 url 的末尾添加一个随机参数。例如

<img src="files/adaptive_filter.png?1" alt="Schema of adaptive filter" height="100">

不会和

缓存在同一个地方
<img src="files/adaptive_filter.png?2" alt="Schema of adaptive filter" height="100">

执行此操作的一种编程方式是通过 python 包含图片,而不是 markdown,例如:

# pick a random integer with 1 in 2 billion chance of getting the same
# integer twice
import random
__counter__ = random.randint(0,2e9)

# now use IPython's rich display to display the html image with the
# new argument
from IPython.display import HTML, display
display(HTML('<img src="files/adaptive_filter.png?%d" ' +
'alt="Schema of adaptive filter" ' +
'height="100">' % __counter__))

应该在每次运行代码单元格时更新图像

关于python - 如何在 ipython 笔记本中重新加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com