python - Jupyter 在打印之前不显示多处理的 matplotlib 图
问题描述
我正在处理一个大数据集,我想并行绘制它以加快速度。我可以轻松地创建绘图并将它们保存到磁盘,但是当我在每个进程中强制打印时,它们只会出现在我的 JupyterLab 笔记本中。有什么办法可以避免打印吗?
%matplotlib inline
def task(args):
i, path = args
print("WHY PYTHON WHY???") # <-- plot will not be visible without this
matplotlib.font_manager._get_font.cache_clear() # necessary to reduce corruption artifacts
values = range(10000)
plt.figure(figsize=(40,10))
plt.violinplot(values)
plt.show()
plt.savefig(path)
return i
paths = [f"figs/{i}.png" for i in range(9)]
with Pool(10) as pool:
for i in pool.imap(task, zip(range(9), paths)):
pass
解决方案
推荐阅读
- javascript - 如何更改所有 AJAX 请求以从 cookie 添加令牌标头
- laravel - Laravel 字体扩展验证
- javascript - jQuery 根据输入设置和触发选项值
- php - 如何从我单击的任务中获取 id
- python - 在使用列表推导生成素数时使用 `all()` 函数
- google-chrome-extension - 每次使用弹出窗口时显示一个新链接
- uwp - 鼠标和键盘滞后于新部署的 UWP 应用
- angular - 将传入的整数值绑定到表单组中的 mat-radio-button 值
- java - 未检测到 Java KeyPress
- .net - ASP.NET MVC - 不能在 Foreach 循环中使用 HTML Raw