Skip to content
Snippets Groups Projects
notebooks.ipynb 3.3 KiB
Newer Older
Paul Gierz's avatar
Paul Gierz committed
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Content with notebooks\n",
    "\n",
    "You can also create content with Jupyter Notebooks. This means that you can include\n",
    "code blocks and their outputs in your book.\n",
    "\n",
    "## Markdown + notebooks\n",
    "\n",
    "As it is markdown, you can embed images, HTML, etc into your posts!\n",
    "\n",
    "![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)\n",
    "\n",
    "You can also $add_{math}$ and\n",
    "\n",
    "$$\n",
    "math^{blocks}\n",
    "$$\n",
    "\n",
    "or\n",
    "\n",
    "$$\n",
    "\\begin{aligned}\n",
    "\\mbox{mean} la_{tex} \\\\ \\\\\n",
    "math blocks\n",
    "\\end{aligned}\n",
    "$$\n",
    "\n",
    "But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n",
    "\n",
    "## MyST markdown\n",
    "\n",
    "MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n",
    "out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n",
    "or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n",
    "\n",
    "## Code blocks and 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": {},
   "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": [
    "There is a lot more that you can do with outputs (such as including interactive outputs)\n",
    "with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.0"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}