.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery-examples/sphinx-gallery.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery-examples_sphinx-gallery.py: 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: .. code-block:: bash pip install sphinx-gallery Then, add the package to the ``extensions`` variable in your Sphinx ``conf.py`` file: .. code-block:: python extensions = [ "sphinx_gallery.gen_gallery", ] .. GENERATED FROM PYTHON SOURCE LINES 46-49 Plot a simple sphere using PyVista ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This code plots a simple sphere using PyVista. .. GENERATED FROM PYTHON SOURCE LINES 49-57 .. code-block:: Python import pyvista as pv pv.set_jupyter_backend("html") sphere = pv.Sphere() sphere.plot() .. image-sg:: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_001.png :alt: sphinx gallery :srcset: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 Plot a simple sphere using PyVista with a plotter .. GENERATED FROM PYTHON SOURCE LINES 59-65 .. code-block:: Python plotter = pv.Plotter(notebook=True) plotter.add_mesh(sphere, color="white", show_edges=True) plotter.title = "3D Sphere Visualization" plotter.show() .. image-sg:: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_002.png :alt: sphinx gallery :srcset: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none EmbeddableWidget(value='') .. GENERATED FROM PYTHON SOURCE LINES 66-69 Figures with Matplotlib ~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to render a figure using Matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 69-85 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np time = np.linspace(0, 2 * np.pi, 100) fig, ax = plt.subplots() ax.plot(time, np.cos(time), color="blue", label=r"$\cos{(t)}$") ax.plot(time, np.sin(time), color="red", label=r"$\sin{(t)}$") ax.set_xlabel("Time [time units]") ax.set_ylabel("Amplitude [distance units]") ax.set_title("Trigonometric functions") plt.show() .. image-sg:: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_003.png :alt: Trigonometric functions :srcset: /examples/gallery-examples/images/sphx_glr_sphinx-gallery_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-89 Figures with Plotly ~~~~~~~~~~~~~~~~~~~ This example shows how to render a figure using Plotly. .. GENERATED FROM PYTHON SOURCE LINES 89-102 .. code-block:: Python import plotly.graph_objs as go # More info: https://plotly.com/python/renderers/ time = np.linspace(0, 2 * np.pi, 100) cos_trace = go.Scatter(x=time, y=np.cos(time), mode="lines", name="cos(t)") sin_trace = go.Scatter(x=time, y=np.sin(time), mode="lines", name="sin(t)") fig = go.Figure(data=[cos_trace, sin_trace]) fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 103-120 .. code-block:: Python import numpy as np import plotly.express as px df = px.data.tips() fig = px.bar( df, x="sex", y="total_bill", facet_col="day", color="smoker", barmode="group", template="presentation+plotly", ) fig.update_layout(height=400) fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 121-124 Render equations using IPython ``math`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to render equations using the IPython ``math`` module. .. GENERATED FROM PYTHON SOURCE LINES 124-132 .. code-block:: Python 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)) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 133-137 .. code-block:: Python from IPython.display import Latex Latex(r"This is a \LaTeX{} equation: $a^2 + b^2 = c^2$") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 138-154 Render a table ~~~~~~~~~~~~~~ This is an example to render a table with Sphinx-Gallery. +--------------------------------+--------------------------------+------------------------------+ | A | B | A and B | +================================+================================+==============================+ | False | False | False | +--------------------------------+--------------------------------+------------------------------+ | True | False | False | +--------------------------------+--------------------------------+------------------------------+ | False | True | False | +--------------------------------+--------------------------------+------------------------------+ | True | True | True | +--------------------------------+--------------------------------+------------------------------+ .. GENERATED FROM PYTHON SOURCE LINES 156-157 Render a table using pandas .. GENERATED FROM PYTHON SOURCE LINES 157-173 .. code-block:: Python 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() .. raw:: html
A B C
0 True False True
1 False True True
2 True False False
3 False True False


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.829 seconds) .. _sphx_glr_download_examples_gallery-examples_sphinx-gallery.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sphinx-gallery.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sphinx-gallery.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sphinx-gallery.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_