Skip to content

Commit eb1ff39

Browse files
authored
Reduce footprint in intro notebook (#347)
* Create some basic ascii art in notebook. * Remove extra dependencies
1 parent 0aebaac commit eb1ff39

File tree

3 files changed

+22
-55
lines changed

3 files changed

+22
-55
lines changed

python-project-template/pyproject.toml.jinja

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ dev = [
5353
"nbconvert", # Needed for pre-commit check to clear output from Python notebooks
5454
"nbsphinx", # Used to integrate Python notebooks into Sphinx documentation
5555
"ipython", # Also used in building notebooks into Sphinx
56-
"matplotlib", # Used in sample notebook intro_notebook.ipynb
57-
"numpy", # Used in sample notebook intro_notebook.ipynb
5856
{%- endif %}
5957
{%- if include_benchmarks %}
6058
"asv==0.6.1", # Used to compute performance benchmarks

python-project-template/{% if include_docs %}docs{% endif %}/notebooks/{% if include_notebooks %}intro_notebook.ipynb{% endif %}

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"cell_marker": "\"\"\""
88
},
99
"source": [
10-
"# Introducing Jupyter Notebooks\n",
10+
"# Introducing Jupyter Notebooks in Sphinx\n",
1111
"\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",
1313
"\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)"
1517
]
1618
},
1719
{
@@ -21,18 +23,17 @@
2123
"metadata": {},
2224
"outputs": [],
2325
"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))"
3637
]
3738
},
3839
{
@@ -43,56 +44,26 @@
4344
"lines_to_next_cell": 1
4445
},
4546
"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."
4748
]
4849
},
4950
{
5051
"cell_type": "code",
5152
"execution_count": null,
52-
"id": "funded-protection",
53-
"metadata": {
54-
"lines_to_next_cell": 1
55-
},
53+
"metadata": {},
5654
"outputs": [],
5755
"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)"
8658
]
8759
},
8860
{
8961
"cell_type": "code",
9062
"execution_count": null,
91-
"id": "imported-uruguay",
9263
"metadata": {},
9364
"outputs": [],
9465
"source": [
95-
"SineAndCosineWaves()"
66+
"sierpinsky(4)"
9667
]
9768
}
9869
],
@@ -104,7 +75,7 @@
10475
"display_name": "Python 3",
10576
"language": "python",
10677
"name": "python3"
107-
}
78+
}
10879
},
10980
"nbformat": 4,
11081
"nbformat_minor": 5

python-project-template/{% if include_docs %}docs{% endif %}/requirements.txt.jinja

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ nbsphinx
66
ipython
77
jupytext
88
jupyter
9-
matplotlib
10-
numpy
119
{%- endif %}

0 commit comments

Comments
 (0)