跳至内容
Hextra v0.12 发布啦!🎉 查看更新内容
Jupyter Notebook

Jupyter Notebook 组件

实验性功能:通过短代码嵌入 Jupyter Notebook。注意并非所有单元格类型都受支持。

Jupyter NotebookProject Jupyter 推出的语言无关的 HTML 笔记本应用。它允许你创建和分享包含动态代码、数学公式、可视化图表和叙述性文本的文档。

使用方法

使用本地笔记本

要使用 Jupyter Notebook 短代码,你需要在项目中放置一个 Jupyter Notebook 文件。与添加图片到项目类似,你可以将 Jupyter Notebook 放入 assets 文件夹。

    • notebook.ipynb
      • my-page.md

使用 jupyter 短代码将笔记本嵌入页面:

content/docs/my-page.md
---
title: 我的页面
math: true
---

{{% jupyter "notebook.ipynb" %}}

或者,你可以利用 Hugo 的页面包功能,将 Jupyter Notebook 与 Markdown 文件组织在一起。

        • index.md
        • notebook.ipynb
content/docs/my-page/index.md
---
title: 我的页面
math: true
---

{{% jupyter "notebook.ipynb" %}}

使用远程笔记本

你也可以通过提供笔记本文件的 URL 来使用远程笔记本。例如,要在页面中嵌入 什么是 Jupyter Notebook 笔记本,可以使用以下短代码:

{{% jupyter "https://raw.githubusercontent.com/jupyter/notebook/main/docs/source/examples/Notebook/What%20is%20the%20Jupyter%20Notebook.ipynb" %}}

示例笔记本

以下示例展示的是项目 assets 文件夹中包含的笔记本文件。

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",
)
Matplotlib is building the font cache; this may take a moment.
<seaborn.axisgrid.FacetGrid at 0x12830caa0>
image
tips.head()
   total_bill   tip     sex smoker  day    time  size
0       16.99  1.01  Female     No  Sun  Dinner     2
1       10.34  1.66    Male     No  Sun  Dinner     3
2       21.01  3.50    Male     No  Sun  Dinner     3
3       23.68  3.31    Male     No  Sun  Dinner     2
4       24.59  3.61  Female     No  Sun  Dinner     4

total_billtipsexsmokerdaytimesize
016.991.01FemaleNoSunDinner2
110.341.66MaleNoSunDinner3
221.013.50MaleNoSunDinner3
323.683.31MaleNoSunDinner2
424.593.61FemaleNoSunDinner4

Equations

The following is an example of a simple equation using LaTeX.

E=mc2 E = mc^2
最后更新于