|
7 | 7 | "cell_marker": "\"\"\"" |
8 | 8 | }, |
9 | 9 | "source": [ |
10 | | - "# Introducing Jupyter Notebooks\n", |
| 10 | + "# Introducing Jupyter Notebooks in Sphinx\n", |
11 | 11 | "\n", |
12 | | - "_(The example used here is JamesALeedham's notebook: [intro.ipynb](https://github.com/JamesALeedham/Sphinx-Autosummary-Recursion/blob/master/docs/notebooks/intro.ipynb))_\n", |
| 12 | + "This notebook showcases very basic functionality of rendering your jupyter notebooks as tutorials inside your sphinx documentation.\n", |
13 | 13 | "\n", |
14 | | - "First, set up the environment:" |
| 14 | + "As part of the LINCC Frameworks python project template, your notebooks will be executed AND rendered at document build time.\n", |
| 15 | + "\n", |
| 16 | + "You can read more about Sphinx, ReadTheDocs, and building notebooks in [LINCC's documentation](https://lincc-ppt.readthedocs.io/en/latest/practices/sphinx.html)" |
15 | 17 | ] |
16 | 18 | }, |
17 | 19 | { |
|
21 | 23 | "metadata": {}, |
22 | 24 | "outputs": [], |
23 | 25 | "source": [ |
24 | | - "import matplotlib\n", |
25 | | - "import matplotlib.pyplot as pl\n", |
26 | | - "import numpy as np\n", |
27 | | - "\n", |
28 | | - "try:\n", |
29 | | - " from IPython import get_ipython\n", |
30 | | - " get_ipython().run_line_magic('matplotlib', 'inline')\n", |
31 | | - "except AttributeError:\n", |
32 | | - " print('Magic function can only be used in IPython environment')\n", |
33 | | - " matplotlib.use('Agg')\n", |
34 | | - "\n", |
35 | | - "pl.rcParams[\"figure.figsize\"] = [15, 8]" |
| 26 | + "def sierpinsky(order):\n", |
| 27 | + " \"\"\"Define a method that will create a Sierpinsky triangle of given order,\n", |
| 28 | + " and will print it out.\"\"\"\n", |
| 29 | + " triangles = [\"*\"]\n", |
| 30 | + " for i in range(order):\n", |
| 31 | + " spaces = \" \" * (2**i)\n", |
| 32 | + " triangles = [spaces + triangle + spaces for triangle in triangles] + [\n", |
| 33 | + " triangle + \" \" + triangle for triangle in triangles\n", |
| 34 | + " ]\n", |
| 35 | + " print(f\"Printing order {order} triangle\")\n", |
| 36 | + " print(\"\\n\".join(triangles))" |
36 | 37 | ] |
37 | 38 | }, |
38 | 39 | { |
|
43 | 44 | "lines_to_next_cell": 1 |
44 | 45 | }, |
45 | 46 | "source": [ |
46 | | - "Then, define a function that creates a pretty graph:" |
| 47 | + "Then, call our method a few times. This will happen on the fly during notebook rendering." |
47 | 48 | ] |
48 | 49 | }, |
49 | 50 | { |
50 | 51 | "cell_type": "code", |
51 | 52 | "execution_count": null, |
52 | | - "id": "funded-protection", |
53 | | - "metadata": { |
54 | | - "lines_to_next_cell": 1 |
55 | | - }, |
| 53 | + "metadata": {}, |
56 | 54 | "outputs": [], |
57 | 55 | "source": [ |
58 | | - "def SineAndCosineWaves():\n", |
59 | | - " # Get a large number of X values for a nice smooth curve. Using Pi as np.sin requires radians...\n", |
60 | | - " x = np.linspace(0, 2 * np.pi, 180)\n", |
61 | | - " # Convert radians to degrees to make for a meaningful X axis (1 radian = 57.29* degrees)\n", |
62 | | - " xdeg = 57.29577951308232 * np.array(x)\n", |
63 | | - " # Calculate the sine of each value of X\n", |
64 | | - " y = np.sin(x)\n", |
65 | | - " # Calculate the cosine of each value of X\n", |
66 | | - " z = np.cos(x)\n", |
67 | | - " # Plot the sine wave in blue, using degrees rather than radians on the X axis\n", |
68 | | - " pl.plot(xdeg, y, color='blue', label='Sine wave')\n", |
69 | | - " # Plot the cos wave in green, using degrees rather than radians on the X axis\n", |
70 | | - " pl.plot(xdeg, z, color='green', label='Cosine wave')\n", |
71 | | - " pl.xlabel(\"Degrees\")\n", |
72 | | - " # More sensible X axis values\n", |
73 | | - " pl.xticks(np.arange(0, 361, 45))\n", |
74 | | - " pl.legend()\n", |
75 | | - " pl.show()" |
76 | | - ] |
77 | | - }, |
78 | | - { |
79 | | - "cell_type": "markdown", |
80 | | - "id": "thorough-cutting", |
81 | | - "metadata": { |
82 | | - "cell_marker": "\"\"\"" |
83 | | - }, |
84 | | - "source": [ |
85 | | - "Finally, call that function to display the graph:" |
| 56 | + "for order in range(3):\n", |
| 57 | + " sierpinsky(order)" |
86 | 58 | ] |
87 | 59 | }, |
88 | 60 | { |
89 | 61 | "cell_type": "code", |
90 | 62 | "execution_count": null, |
91 | | - "id": "imported-uruguay", |
92 | 63 | "metadata": {}, |
93 | 64 | "outputs": [], |
94 | 65 | "source": [ |
95 | | - "SineAndCosineWaves()" |
| 66 | + "sierpinsky(4)" |
96 | 67 | ] |
97 | 68 | } |
98 | 69 | ], |
|
104 | 75 | "display_name": "Python 3", |
105 | 76 | "language": "python", |
106 | 77 | "name": "python3" |
107 | | - } |
| 78 | + } |
108 | 79 | }, |
109 | 80 | "nbformat": 4, |
110 | 81 | "nbformat_minor": 5 |
|
0 commit comments