Tertiary example - Plotting sin3

This is a general example demonstrating a Matplotlib plot output, embedded rST, the use of math notation and cross-linking to other examples. It would be useful to compare with the output below.

\[x \rightarrow \sin(x)\]

Here the function \(\sin\) is evaluated at each point the variable \(x\) is defined.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

plt.plot(x, y)
plt.xlabel('$x$')
plt.ylabel('$\sin(x)$')
# To avoid matplotlib text output
plt.show()
../_images/sphx_glr_ex3_001.png

To include embedded rST, use a line of >= 20 #’s or #%% between your rST and your. This separates your example into distinct text and code blocks. You can continue writing code below the embedded rST text block:

print('This example shows a sin plot!')

Out:

This example shows a sin plot!
from py_qs_example.mymodule import ExampleClass, example_function, less_important_function
ec = ExampleClass(5)
ec

Out:

example
output = example_function(ec, '_test')
output

Out:

'example_test'

LaTeX syntax in the text blocks does not require backslashes to be escaped:

\[\sin\]

Cross referencing

You can refer to an example from any part of the documentation, including from other examples. Sphinx-Gallery automatically creates reference labels for each example. The label consists of the .py file name, prefixed with sphx_glr_ and the name of the folder(s) the example is in. In this case, the example we want to cross-reference is in auto_examples (the gallery_dirs; see

Total running time of the script: ( 0 minutes 0.212 seconds)

Gallery generated by Sphinx-Gallery