|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Content with notebooks\n", |
| 8 | + "\n", |
| 9 | + "You can also create content with Jupyter Notebooks. This means that you can include\n", |
| 10 | + "code blocks and their outputs in your book.\n", |
| 11 | + "\n", |
| 12 | + "## Markdown + notebooks\n", |
| 13 | + "\n", |
| 14 | + "As it is markdown, you can embed images, HTML, etc into your posts!\n", |
| 15 | + "\n", |
| 16 | + "\n", |
| 17 | + "\n", |
| 18 | + "You can also $add_{math}$ and\n", |
| 19 | + "\n", |
| 20 | + "$$\n", |
| 21 | + "math^{blocks}\n", |
| 22 | + "$$\n", |
| 23 | + "\n", |
| 24 | + "or\n", |
| 25 | + "\n", |
| 26 | + "$$\n", |
| 27 | + "\\begin{aligned}\n", |
| 28 | + "\\mbox{mean} la_{tex} \\\\ \\\\\n", |
| 29 | + "math blocks\n", |
| 30 | + "\\end{aligned}\n", |
| 31 | + "$$\n", |
| 32 | + "\n", |
| 33 | + "But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n", |
| 34 | + "\n", |
| 35 | + "## MyST markdown\n", |
| 36 | + "\n", |
| 37 | + "MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n", |
| 38 | + "out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n", |
| 39 | + "or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n", |
| 40 | + "\n", |
| 41 | + "## Code blocks and outputs\n", |
| 42 | + "\n", |
| 43 | + "Jupyter Book will also embed your code blocks and output in your book.\n", |
| 44 | + "For example, here's some sample Matplotlib code:" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": null, |
| 50 | + "metadata": {}, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "from matplotlib import rcParams, cycler\n", |
| 54 | + "import matplotlib.pyplot as plt\n", |
| 55 | + "import numpy as np\n", |
| 56 | + "plt.ion()" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "# Fixing random state for reproducibility\n", |
| 66 | + "np.random.seed(19680801)\n", |
| 67 | + "\n", |
| 68 | + "N = 10\n", |
| 69 | + "data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n", |
| 70 | + "data = np.array(data).T\n", |
| 71 | + "cmap = plt.cm.coolwarm\n", |
| 72 | + "rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n", |
| 73 | + "\n", |
| 74 | + "\n", |
| 75 | + "from matplotlib.lines import Line2D\n", |
| 76 | + "custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n", |
| 77 | + " Line2D([0], [0], color=cmap(.5), lw=4),\n", |
| 78 | + " Line2D([0], [0], color=cmap(1.), lw=4)]\n", |
| 79 | + "\n", |
| 80 | + "fig, ax = plt.subplots(figsize=(10, 5))\n", |
| 81 | + "lines = ax.plot(data)\n", |
| 82 | + "ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "markdown", |
| 87 | + "metadata": {}, |
| 88 | + "source": [ |
| 89 | + "There is a lot more that you can do with outputs (such as including interactive outputs)\n", |
| 90 | + "with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)" |
| 91 | + ] |
| 92 | + } |
| 93 | + ], |
| 94 | + "metadata": { |
| 95 | + "kernelspec": { |
| 96 | + "display_name": "Python 3", |
| 97 | + "language": "python", |
| 98 | + "name": "python3" |
| 99 | + }, |
| 100 | + "language_info": { |
| 101 | + "codemirror_mode": { |
| 102 | + "name": "ipython", |
| 103 | + "version": 3 |
| 104 | + }, |
| 105 | + "file_extension": ".py", |
| 106 | + "mimetype": "text/x-python", |
| 107 | + "name": "python", |
| 108 | + "nbconvert_exporter": "python", |
| 109 | + "pygments_lexer": "ipython3", |
| 110 | + "version": "3.8.0" |
| 111 | + }, |
| 112 | + "widgets": { |
| 113 | + "application/vnd.jupyter.widget-state+json": { |
| 114 | + "state": {}, |
| 115 | + "version_major": 2, |
| 116 | + "version_minor": 0 |
| 117 | + } |
| 118 | + } |
| 119 | + }, |
| 120 | + "nbformat": 4, |
| 121 | + "nbformat_minor": 4 |
| 122 | +} |
0 commit comments