Jupyter Lab 常用插件

Jupyter Lab 常用插件安装与使用指南
Jupyter Lab 支持许多有用的插件,这些插件可以显著增强其功能。以下是一些常用插件的详细安装和使用方法。

1. 中文语言包
安装和使用步骤
安装 JupyterLab-Translate 扩展:
pip install jupyterlab-translate
jupyter labextension install jupyterlab-translate

安装中文语言包:
pip install jupyterlab-zh-CN

启动 Jupyter Lab,切换语言:
打开 Jupyter Lab 后,点击右上角的 “Settings” 菜单。
选择 “Language”。
在弹出的对话框中选择 “简体中文”(Simplified Chinese)。
重启 Jupyter Lab,界面应该切换到中文。


2. LaTeX 支持
安装和使用步骤
安装 LaTeX 插件:
pip install jupyterlab-latex
jupyter labextension install @jupyterlab/latex

启动 Jupyter Lab,并打开 LaTeX 文件:
在文件浏览器中双击 .tex 文件,即可查看和编辑 LaTeX 文档。
使用工具栏上的按钮编译和查看 PDF 预览。


3. HTML 预览
安装和使用步骤
安装 HTML 预览插件:
jupyter labextension install @jupyterlab/htmlviewer

启动 Jupyter Lab,并打开 HTML 文件:
在文件浏览器中双击 .html 文件,即可查看 HTML 文件的内容。


4. Plotly 支持
安装和使用步骤
安装 Plotly:
pip install plotly
jupyter labextension install jupyterlab-plotly

使用 Plotly 绘图:
import plotly.express as px

df = px.data.iris()
fig = px.scatter(df, x='sepal_width', y='sepal_length', color='species')
fig.show()

 

5. Bokeh 支持
安装和使用步骤
安装 Bokeh:
pip install bokeh

使用 Bokeh 绘图:
from bokeh.plotting import figure, output_notebook, show
output_notebook()
p = figure(title="Simple Line Example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)

 

6. Matplotlib 支持
Matplotlib 是 Jupyter Lab 内置支持的。

使用 Matplotlib 绘图:
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.ylabel('some numbers')
plt.show()

 

7. Draw.io 图形编辑
安装和使用步骤
安装 Draw.io 插件:
jupyter labextension install jupyterlab-drawio

使用 Draw.io 创建和编辑图形:
在文件浏览器中右键点击选择 “New” > “Diagram”。
使用 Draw.io 界面创建和编辑图形。


8. SQL 支持
安装和使用步骤
安装 SQL 插件:
pip install ipython-sql

使用 SQL 查询:
%load_ext sql
%sql sqlite://
%sql CREATE TABLE test (a INT, b INT)
%sql INSERT INTO test VALUES (1, 2)
%sql SELECT * FROM test

 

9. Variable Inspector
安装和使用步骤
安装 Variable Inspector 插件:
jupyter labextension install @lckr/jupyterlab_variableinspector

使用 Variable Inspector:
在左侧栏会显示 Variable Inspector 图标,点击打开变量查看器。
运行代码单元格后,可以在查看器中看到变量及其值。


10. Dash 支持
安装和使用步骤
安装 Dash:
pip install dash

使用 Dash 创建仪表盘:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

app.layout = html.Div([
dcc.Input(id='input', value='initial value', type='text'),
html.Div(id='output')
])

@app.callback(
Output(component_id='output', component_property='children'),
[Input(component_id='input', component_property='value')]
)
def update_output_div(input_value):
return 'You\'ve entered "{}"'.format(input_value)

if __name__ == '__main__':
app.run_server(debug=True)


11. Gather 支持
安装和使用步骤
安装 Gather 插件:
jupyter labextension install @jupyterlab/gather

使用 Gather:
右键点击代码单元格,选择 “Gather to Notebook” 或 “Gather to Script”。
Gather 将提取相关代码并生成新的笔记本或脚本。


12. Go to Definition 支持
安装和使用步骤
安装插件:
pip install jupyterlab-go-to-definition
jupyter labextension install @krassowski/jupyterlab-go-to-definition

使用 Go to Definition:
在代码单元格中右键点击某个函数或变量,选择 “Go to Definition”。


13. Language Server Protocol (LSP)
安装和使用步骤
安装 LSP 插件:
pip install jupyterlab-lsp
jupyter labextension install @krassowski/jupyterlab-lsp

安装所需语言的服务器,例如,Python 语言服务器:
pip install 'python-lsp-server[all]'

使用 LSP 功能:
打开代码文件或笔记本,LSP 功能会自动启用。
代码自动补全、语法检查和文档提示等功能将会生效。


14. Spreadsheet 支持
安装和使用步骤
安装 SpreadSheet 插件:
jupyter labextension install @jupyterlab/spreadsheet

使用 SpreadSheet:
在文件浏览器中右键点击选择 “New” > “Spreadsheet”。
使用 SpreadSheet 界面编辑和管理表格数据。


15. JupyterLab-Git
JupyterLab-Git 插件为 Jupyter Lab 提供了 Git 版本控制的集成。

安装步骤
安装 Python 包:
pip install jupyterlab-git

安装 Jupyter Lab 扩展:
jupyter labextension install @jupyterlab/git

安装 NodeJS(如果没有安装):
conda install -c conda-forge nodejs

启动 Jupyter Lab 并启用扩展:
jupyter lab

使用方法
在左侧栏会显示 Git 图标,点击打开 Git 面板。
通过面板可以执行 Git 操作,如提交、更改日志查看、分支管理等。


16. JupyterLab-Toc
JupyterLab-Toc 插件为 Jupyter Lab 提供了一个目录功能,可以方便地导航笔记本中的内容。

安装步骤
安装 Jupyter Lab 扩展:
jupyter labextension install @jupyterlab/toc

启动 Jupyter Lab 并启用扩展:
jupyter lab

使用方法
在左侧栏会显示 TOC 图标,点击打开目录视图。
目录视图会自动根据笔记本中的标题生成,点击条目可以快速跳转到相应部分。

posted @ 2024-09-04 10:10  vicowong  阅读(2481)  评论(0)    收藏  举报