Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NuriaQueralt committed Jun 6, 2024
1 parent a57dfee commit 27b3235
Show file tree
Hide file tree
Showing 28 changed files with 4,292 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 5f5f92eb960a2a0d728d5ca388863ca6
config: 8e2a1daa6ba7f8792b36e7fab37db85c
tags: 645f666f9bcd5a90fca523b33c5a78b7
354 changes: 354 additions & 0 deletions _downloads/ff16d68c043fddf425231f53922ef2eb/notebooks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(file-types:notebooks)=\n",
"# Jupyter Notebook files\n",
"\n",
"You can create content with Jupyter notebooks.\n",
"For example, the content for the current page is contained in {download}`this notebook file <./notebooks.ipynb>`.\n",
"\n",
"```{margin}\n",
"If you'd like to write in plain-text files, but still keep a notebook structure, you can write\n",
"Jupyter notebooks with MyST Markdown, which are then automatically converted to notebooks.\n",
"See [](./myst-notebooks.md) for more details.\n",
"```\n",
"\n",
"Jupyter Book supports all Markdown that is supported by Jupyter Notebook.\n",
"This is mostly a flavour of Markdown called [CommonMark Markdown](https://commonmark.org/) with minor modifications.\n",
"For more information about writing Jupyter-flavoured Markdown in Jupyter Book, see [](./markdown.md).\n",
"\n",
"## Code blocks and image outputs\n",
"\n",
"Jupyter Book will also embed your code blocks and output in your book.\n",
"For example, here's some sample Matplotlib code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import rcParams, cycler\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"plt.ion()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-stdout"
]
},
"outputs": [],
"source": [
"# Fixing random state for reproducibility\n",
"np.random.seed(19680801)\n",
"\n",
"N = 10\n",
"data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n",
"data = np.array(data).T\n",
"cmap = plt.cm.coolwarm\n",
"rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n",
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
"ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the image above is captured and displayed in your site."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"popout",
"remove-input",
"remove-stdout"
]
},
"outputs": [],
"source": [
"# Fixing random state for reproducibility\n",
"np.random.seed(19680801)\n",
"\n",
"N = 10\n",
"data = [np.logspace(0, 1, 100) + .1*np.random.randn(100) + ii for ii in range(N)]\n",
"data = np.array(data).T\n",
"cmap = plt.cm.coolwarm\n",
"rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n",
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
"ax.legend(custom_lines, ['Cold', 'Medium', 'Hot'])\n",
"ax.set(title=\"Smoother linez\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"popout"
]
},
"source": [
"```{margin} **You can also pop out content to the side!**\n",
"For more information on how to do this,\n",
"check out the {ref}`layout/sidebar` section.\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Removing content before publishing\n",
"\n",
"You can also remove some content before publishing your book to the web. \n",
"For reference, {download}`you can download the notebook content for this page <notebooks.ipynb>`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"thisvariable = \"none of this should show up in the textbook\"\n",
"\n",
"fig, ax = plt.subplots()\n",
"x = np.random.randn(100)\n",
"y = np.random.randn(100)\n",
"ax.scatter(x, y, s=np.abs(x*100), c=x, cmap=plt.cm.coolwarm)\n",
"ax.text(0, .5, thisvariable, fontsize=20, transform=ax.transAxes)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can **remove only the code** so that images and other output still show up."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"thisvariable = \"this plot *will* show up in the textbook.\"\n",
"\n",
"fig, ax = plt.subplots()\n",
"x = np.random.randn(100)\n",
"y = np.random.randn(100)\n",
"ax.scatter(x, y, s=np.abs(x*100), c=x, cmap=plt.cm.coolwarm)\n",
"ax.text(0, .5, thisvariable, fontsize=20, transform=ax.transAxes)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Which works well if you'd like to quickly display cell output without cluttering your content with code.\n",
"This works for any cell output, like a Pandas DataFrame."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"import pandas as pd\n",
"pd.DataFrame([['hi', 'there'], ['this', 'is'], ['a', 'DataFrame']], columns=['Word A', 'Word B'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See {ref}`hiding/remove-content` for more information about hiding and removing content."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Interactive outputs\n",
"\n",
"We can do the same for *interactive* material. Below we'll display a map\n",
"using [folium](https://python-visualization.github.io/folium/). When your book is built,\n",
"the code for creating the interactive map is retained.\n",
"\n",
"```{margin}\n",
"**This will only work for some packages.** They need to be able to output standalone\n",
"HTML/Javascript, and not\n",
"depend on an underlying Python kernel to work.\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import folium\n",
"m = folium.Map(\n",
" location=[45.372, -121.6972],\n",
" zoom_start=12,\n",
" tiles='Stamen Terrain'\n",
")\n",
"\n",
"folium.Marker(\n",
" location=[45.3288, -121.6625],\n",
" popup='Mt. Hood Meadows',\n",
" icon=folium.Icon(icon='cloud')\n",
").add_to(m)\n",
"\n",
"folium.Marker(\n",
" location=[45.3311, -121.7113],\n",
" popup='Timberline Lodge',\n",
" icon=folium.Icon(color='green')\n",
").add_to(m)\n",
"\n",
"folium.Marker(\n",
" location=[45.3300, -121.6823],\n",
" popup='Some Other Location',\n",
" icon=folium.Icon(color='red', icon='info-sign')\n",
").add_to(m)\n",
"\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rich outputs from notebook cells"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Because notebooks have rich text outputs, you can store these in\n",
"your Jupyter Book as well! For example, here is the command line help\n",
"menu, see how it is nicely formatted."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!jupyter-book build --help"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And here is an error. You can mark notebook cells as \"expected to error\" by adding a\n",
"`raises-exception` tag to them."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"source": [
"this_will_error"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## More features with Jupyter notebooks\n",
"\n",
"There are many other features of Jupyter notebooks to take advantage of,\n",
"such as automatically generating Binder links for notebooks or connecting your content with a kernel in the cloud.\n",
"For more information browse the pages in this site, and [](content:code-outputs) in particular."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 27b3235

Please sign in to comment.