Note
Go to the end to download the full example code.
Sphinx-Gallery#
This example shows how to add a new example when using Sphinx-Gallery.
To use Sphinx-Gallery, first install the package with this command:
pip install sphinx-gallery
Then, add the package to the extensions
variable in your Sphinx conf.py
file:
extensions = [
"sphinx_gallery.gen_gallery",
]
Plot a simple sphere using PyVista#
This code plots a simple sphere using PyVista.
import pyvista as pv
pv.set_jupyter_backend("html")
sphere = pv.Sphere()
sphere.plot()
Plot a simple sphere using PyVista with a plotter
plotter = pv.Plotter(notebook=True)
plotter.add_mesh(sphere, color="white", show_edges=True)
plotter.title = "3D Sphere Visualization"
plotter.show()
Render equations using IPython math
#
This example shows how to render equations using the IPython math
module.
from IPython.display import Math, display
# LaTeX formatted equation
equation = r"\int\limits_{-\infty}^\infty f(x) \delta(x - x_0) \, dx = f(x_0)"
# Display the equation
display(Math(equation))
from IPython.display import Latex
Latex(r"This is a \LaTeX{} equation: $a^2 + b^2 = c^2$")
Render a table in markdown#
This is an example to render a table inside the markdown with Sphinx-Gallery.
A |
B |
A and B |
---|---|---|
False |
False |
False |
True |
False |
False |
False |
True |
False |
True |
True |
True |
Render a table using pandas
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()