我正在尝试使用 JupyterLab 在循环中更新交互式 matplotlib 图形。如果我在与循环不同的单元格中创建图形,我就可以执行此操作,但我更愿意创建图形并在同一单元格中运行循环。
简单代码示例:
import matplotlib.pyplot as plt
import time
%matplotlib widget
fig = plt.figure()
for i in range(5):
x = list(range(i+2))
xx = [x**2 for x in x]
plt.clf()
plt.plot(x, xx)
fig.canvas.draw()
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
如果fig = plt.figure()与循环位于同一单元格中,则在循环完成之前不会更新图形:
如果我在不同的单元格中创建图形,我会得到动态更新,但如果可能的话,我希望能够在同一单元格中创建图形,以便输出位于循环下方:
我在其他问题中尝试了几个答案(此处、此处和此处),但是它们似乎不适用于 JupyterLab 中的交互式图形。我使用jupyter/scipy-notebook docker 镜像作为我的环境,所以我相信一切都设置正确。
有什么方法可以在创建图形的同一单元格中获得动态更新吗?
Jupyter 实验室笔记本中是否有键盘快捷键可以选择单行(当前行,标记所在的位置)?
我想显示一个文件选择对话框,JupyterLab 笔记本的用户可以从其工作区中选择文件(= 服务器上的文件,而不是本地计算机上的文件)。
如果我尝试使用一些 python 库(tkinter、qt),它将尝试在服务器上打开 GUI。但是,我想在客户端上有一个 GUI。由于客户端在浏览器中运行,因此该 GUI 需要基于 html/javascript。
此外,要选择的文件位于服务器上。可以使用系统命令(例如“!dir”)显示现有文件的列表。
JupyterLab 中似乎有用于文件选择的小部件:
https://jupyterlab.readthedocs.io/en/stable/developer/ui_helpers.html#file-dialogs
JavaScript 代码(需要 Jupyterlab 扩展的构建步骤;FileDialog需要从 @jupyterlab/filebrowser 导入;DocumentManager 需要作为插件依赖项从 @jupyterlab/docmanager 注入;):
var { FileDialog } = require('@jupyterlab/filebrowser');
const dialog = FileDialog.getOpenFiles({
manager, // IDocumentManager
filter: model => model.type == 'notebook' // optional (model: Contents.IModel) => boolean
});
const result = await dialog;
if(result.button.accept){
let files = result.value;
}
Run Code Online (Sandbox Code Playgroud)
=>我如何在我的Python代码中使用这些小部件?是否有一些额外的 python 库可以做到这一点?
不幸的是,FileDialog似乎不包含在ipywidgets:
import ipywidgets as widgets
print(dir(widgets))
Run Code Online (Sandbox Code Playgroud)
有关的:
https://discourse.jupyter.org/t/jupyterlab-file-chooser-widget-server-side/4934/3
ipywidgets
我在 JupyterLab 中有一个名为 myfolder 的文件夹(包含多个文件)。我可以下载文件,但不能下载文件夹,因为 JupyterLab 不允许。因此,我想压缩该文件夹,然后将其下载到我的桌面上。
问题:如何压缩我的文件夹?
这个不起作用:JupyterLab 的下载文件夹
我试过
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:60% !important; }</style>"))
Run Code Online (Sandbox Code Playgroud)
从这个答案来看。我也尝试过
%%html
<style>.container { width:60% !important; }</style>
Run Code Online (Sandbox Code Playgroud)
但它们不起作用。
我想按照我的 jupyter 笔记本中的代码中的顺序打印数据框和绘图:
目前,它们被打印为:
from IPython.display import display
import matplotlib.pyplot as plt
df = pd.DataFrame({'x': range(5), 'y': range(5)})
for i in range(2):
display(df)
display(df.plot())
Run Code Online (Sandbox Code Playgroud)
我在 Julia x Jupyter 项目中,我选择使用jupyter/datascience-notebook Docker Image,其中包含 jupyterlab 和 Julia 环境。
我想知道 Julia 预安装了哪些软件包jupyter/datascience-notebook,并知道我需要手动安装哪些额外软件包。
我阅读了datascience-notebook 的 Dockerfile以了解jupyter/datascience-notebook映像中安装了哪些包,但我找不到用于指定 julia 包的行。
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/scipy-notebook
FROM $BASE_CONTAINER
LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"
# Fix DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
USER root
# Julia installation
# Default values can be overridden at build time
# (ARGS are in lower …Run Code Online (Sandbox Code Playgroud) 我在 ArchLinux 上遇到了 jupyter 扩展的问题。特别是,我收到以下错误:
[W 2023-04-01 18:34:36.504 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_nbextensions_configurator. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[W 2023-04-01 18:34:36.493 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
Run Code Online (Sandbox Code Playgroud)
我怎样才能摆脱这个错误/警告?我尝试用 Pip 删除这些功能,但没有成功。有任何想法吗?
此代码在jupyter笔记本中有效,但在jupyterlab中不起作用:
import ipywidgets as widgets
from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
Run Code Online (Sandbox Code Playgroud)
有没有人有办法解决吗 ?
信封:
jupyter-lab ×10
python ×5
julia ×2
jupyter ×2
matplotlib ×2
css ×1
docker ×1
events ×1
html ×1
ipython ×1
pandas ×1
python-3.x ×1