|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# PyData Library Styles\n", |
| 8 | + "\n", |
| 9 | + "This theme has built-in support and special styling for several major visualization libraries in the PyData ecosystem.\n", |
| 10 | + "This ensures that the images and output generated by these libraries looks good for both light and dark modes.\n", |
| 11 | + "Below are examples of each that we use as a benchmark for reference.\n", |
| 12 | + "\n", |
| 13 | + "## Pandas" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": null, |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "import string\n", |
| 23 | + "\n", |
| 24 | + "import numpy as np\n", |
| 25 | + "import pandas as pd\n", |
| 26 | + "\n", |
| 27 | + "rng = np.random.default_rng()\n", |
| 28 | + "data = rng.standard_normal((100, 26))\n", |
| 29 | + "df = pd.DataFrame(data, columns=list(string.ascii_lowercase))\n", |
| 30 | + "df" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "## Matplotlib" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": null, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "import matplotlib.pyplot as plt\n", |
| 47 | + "\n", |
| 48 | + "fig, ax = plt.subplots()\n", |
| 49 | + "ax.scatter(df[\"a\"], df[\"b\"], c=df[\"b\"], s=3)" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "rng = np.random.default_rng()\n", |
| 59 | + "data = rng.standard_normal((3, 100))\n", |
| 60 | + "fig, ax = plt.subplots()\n", |
| 61 | + "ax.scatter(data[0], data[1], c=data[2], s=3)" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "metadata": {}, |
| 67 | + "source": [ |
| 68 | + "## Plotly\n", |
| 69 | + "\n", |
| 70 | + "The HTML below shouldn't display, but it uses RequireJS to make sure that all\n", |
| 71 | + "works as expected. If the widgets don't show up, RequireJS may be broken." |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": null, |
| 77 | + "metadata": {}, |
| 78 | + "outputs": [], |
| 79 | + "source": [ |
| 80 | + "import plotly.io as pio\n", |
| 81 | + "import plotly.express as px\n", |
| 82 | + "import plotly.offline as py\n", |
| 83 | + "\n", |
| 84 | + "pio.renderers.default = \"notebook\"\n", |
| 85 | + "\n", |
| 86 | + "df = px.data.iris()\n", |
| 87 | + "fig = px.scatter(df, x=\"sepal_width\", y=\"sepal_length\", color=\"species\", size=\"sepal_length\")\n", |
| 88 | + "fig" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "markdown", |
| 93 | + "metadata": {}, |
| 94 | + "source": [ |
| 95 | + "## Xarray\n", |
| 96 | + "\n", |
| 97 | + "Here we demonstrate `xarray` to ensure that it shows up properly." |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "code", |
| 102 | + "execution_count": null, |
| 103 | + "metadata": {}, |
| 104 | + "outputs": [], |
| 105 | + "source": [ |
| 106 | + "import xarray as xr\n", |
| 107 | + "data = xr.DataArray(\n", |
| 108 | + " np.random.randn(2, 3),\n", |
| 109 | + " dims=(\"x\", \"y\"),\n", |
| 110 | + " coords={\"x\": [10, 20]}, attrs={\"foo\": \"bar\"}\n", |
| 111 | + " )\n", |
| 112 | + "data" |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "markdown", |
| 117 | + "metadata": {}, |
| 118 | + "source": [ |
| 119 | + "## ipyleaflet\n", |
| 120 | + "\n", |
| 121 | + "`ipyleaflet` is a **Jupyter**/**Leaflet** bridge enabling interactive maps in the Jupyter notebook environment. this demonstrate how you can integrate maps in your documentation." |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "code", |
| 126 | + "execution_count": null, |
| 127 | + "metadata": {}, |
| 128 | + "outputs": [], |
| 129 | + "source": [ |
| 130 | + "from ipyleaflet import Map, basemaps\n", |
| 131 | + "\n", |
| 132 | + "# display a map centered on France\n", |
| 133 | + "m = Map(basemap=basemaps.Esri.WorldImagery, zoom=5, center=[46.21, 2.21])\n", |
| 134 | + "m" |
| 135 | + ] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "Python 3", |
| 141 | + "language": "python", |
| 142 | + "name": "python3" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "name": "python", |
| 146 | + "version": "3.10.8" |
| 147 | + } |
| 148 | + }, |
| 149 | + "nbformat": 4, |
| 150 | + "nbformat_minor": 2 |
| 151 | +} |
0 commit comments