Jupyter Notebook 组件
Jupyter Notebook 是 Project Jupyter 的一个语言无关的 HTML 笔记本应用程序。它允许你创建和共享包含实时代码、方程、可视化和叙述性文本的文档。
使用方法
使用本地笔记本
要使用 Jupyter Notebook 短代码,你需要在项目中有一个 Jupyter Notebook 文件。类似于如何添加图片到项目中,你可以将 Jupyter Notebooks 添加到 assets
文件夹。
- notebook.ipynb
- my-page.md
使用 jupyter
短代码将 Jupyter Notebook 包含在页面中:
---
title: 我的页面
math: true
---
{{% jupyter "notebook.ipynb" %}}
或者,你可以利用 Hugo 的页面包功能将 Jupyter Notebooks 与 Markdown 文件一起组织。
- index.md
- notebook.ipynb
---
title: 我的页面
math: true
---
{{% jupyter "notebook.ipynb" %}}
使用远程笔记本
你也可以通过提供笔记本文件的 URL 来使用远程笔记本。例如,要在页面中包含 What is the Jupyter Notebook 笔记本,你可以使用以下短代码:
{{% jupyter "https://raw.githubusercontent.com/jupyter/notebook/main/docs/source/examples/Notebook/What%20is%20the%20Jupyter%20Notebook.ipynb" %}}
示例笔记本
What is the Jupyter Notebook?
The Jupyter Notebook is an interactive computing environment that enables users to author notebook documents that include:
- Live code
- Interactive widgets
- Plots
- Narrative text
- Equations
- Images
- Video
These documents provide a complete and self-contained record of a computation that can be converted to various formats and shared with others using email, version control systems (like Git/GitHub) or nbviewer.jupyter.org.
Data Visualization
Below is an example of a simple data visualization using the Seaborn library.
# Import seaborn
import seaborn as sns
# Apply the default theme
sns.set_theme()
# Load an example dataset
tips = sns.load_dataset("tips")
# Create a visualization
sns.relplot(
data=tips,
x="total_bill", y="tip", col="time",
hue="smoker", style="smoker", size="size",
)
tips.head()
Equations
The following is an example of a simple equation using LaTeX.
$$ E = mc^2 $$