Jupyter Notebooks#

This page was written for MyST-NB. It demonstrates sphinx-thebe’s usage with Jupyter Notebooks.

Activate Thebe by clicking the launch button below. You should then be able to run and edit the code cell in the notebook.

The outputs should be displayed below, but they will be collected by sphinx-thebe when it is activated so that they are cleared when you first run the cell.

import numpy as np
import matplotlib.pyplot as plt

# Create some fake data
data = np.random.randn(3, 1000)

# Create a figure
fig, ax = plt.subplots()

# Plot data
ax.scatter(data[0], data[1], c=np.abs(data[2]), s=np.abs(data[2])*100)
<matplotlib.collections.PathCollection at 0x7f9427818f10>
../_images/6230a4d5277ccd06af13135fbe13025aa75fa8a478b4cdfc189b6c7f61532d78.png

Code style#

Thebe uses CodeMirror in the background, which uses different styles than pygments, which is used for static code syntax highlighting.

The below code block is static and will not be converted with thebe. We include it in order to compare the active Thebe cell’s syntax highlighting with an inactive cell.

import numpy as np
import matplotlib.pyplot as plt

# Create some fake data
data = np.random.randn(3, 1000)

# Create a figure
fig, ax = plt.subplots()

# Plot data
ax.scatter(data[0], data[1], c=np.abs(data[2]), s=np.abs(data[2])*100)