Download this example as a Jupyter notebook.


Nbsphinx example#

This example renders a Jupyter notebook using the nbsphinx extension.

Plot a simple sphere using PyVista.#

[1]:
import pyvista as pv

pv.set_jupyter_backend('html')

sphere = pv.Sphere()
sphere.plot()
[2]:
plotter = pv.Plotter(notebook=True)
plotter.add_mesh(sphere, color='white', show_edges=True)
plotter.title = '3D Sphere Visualization'
plotter.show()

Render equations using the IPython math module.#

[3]:
from IPython.display import Math
eq = Math(r'\int\limits_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)')
eq
[3]:
$\displaystyle \int\limits_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)$
[4]:
from IPython.display import Latex
Latex(r'This is a \LaTeX{} equation: $a^2 + b^2 = c^2$')
[4]:
This is a \LaTeX{} equation: $a^2 + b^2 = c^2$

Render a table in markdown.#

This is an example to render the table inside the notebook

A

B

A and B

False

False

False

True

False

False

False

True

False

True

True

True

Render a data frame#

[5]:
import pandas as pd

# Create a dictionary of data
data = {
    'A': [True, False, True, False],
    'B': [False, True, False, True],
    'C': [True, True, False, False],
}

# Create DataFrame from the dictionary
df = pd.DataFrame(data)

# Display the DataFrame
df.head()
[5]:
A B C
0 True False True
1 False True True
2 True False False
3 False True False