| 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." |
| 12 |
] |
| 13 |
}, |
| 14 |
{ |
| 15 |
"cell_type": "markdown", |
| 16 |
"metadata": {}, |
| 17 |
"source": [ |
| 18 |
"## Pandas" |
| 19 |
] |
| 20 |
}, |
| 21 |
{ |
| 22 |
"cell_type": "code", |
| 23 |
"execution_count": null, |
| 24 |
"metadata": {}, |
| 25 |
"outputs": [], |
| 26 |
"source": [ |
| 27 |
"import string\n", |
| 28 |
"\n", |
| 29 |
"import numpy as np\n", |
| 30 |
"import pandas as pd\n", |
| 31 |
"\n", |
| 32 |
"\n", |
| 33 |
"rng = np.random.default_rng(seed=15485863)\n", |
| 34 |
"data = rng.standard_normal((100, 26))\n", |
| 35 |
"df = pd.DataFrame(data, columns=list(string.ascii_lowercase))\n", |
| 36 |
"df" |
| 37 |
] |
| 38 |
}, |
| 39 |
{ |
| 40 |
"cell_type": "markdown", |
| 41 |
"metadata": {}, |
| 42 |
"source": [ |
| 43 |
"## IPyWidget" |
| 44 |
] |
| 45 |
}, |
| 46 |
{ |
| 47 |
"cell_type": "code", |
| 48 |
"execution_count": null, |
| 49 |
"metadata": {}, |
| 50 |
"outputs": [], |
| 51 |
"source": [ |
| 52 |
"import ipywidgets as widgets\n", |
| 53 |
"import numpy as np\n", |
| 54 |
"import pandas as pd\n", |
| 55 |
"\n", |
| 56 |
"from IPython.display import display\n", |
| 57 |
"\n", |
| 58 |
"\n", |
| 59 |
"tab = widgets.Tab()\n", |
| 60 |
"\n", |
| 61 |
"descr_str = \"Hello\"\n", |
| 62 |
"\n", |
| 63 |
"title = widgets.HTML(descr_str)\n", |
| 64 |
"\n", |
| 65 |
"# create output widgets\n", |
| 66 |
"widget_images = widgets.Output()\n", |
| 67 |
"widget_annotations = widgets.Output()\n", |
| 68 |
"\n", |
| 69 |
"# render in output widgets\n", |
| 70 |
"with widget_images:\n", |
| 71 |
" display(pd.DataFrame(np.random.randn(10, 10)))\n", |
| 72 |
"with widget_annotations:\n", |
| 73 |
" display(pd.DataFrame(np.random.randn(10, 10)))\n", |
| 74 |
"\n", |
| 75 |
"tab.children = [widget_images, widget_annotations]\n", |
| 76 |
"tab.titles = [\"Images\", \"Annotations\"]\n", |
| 77 |
"\n", |
| 78 |
"display(widgets.VBox([title, tab]))" |
| 79 |
] |
| 80 |
}, |
| 81 |
{ |
| 82 |
"cell_type": "markdown", |
| 83 |
"metadata": {}, |
| 84 |
"source": [ |
| 85 |
"## Matplotlib" |
| 86 |
] |
| 87 |
}, |
| 88 |
{ |
| 89 |
"cell_type": "code", |
| 90 |
"execution_count": null, |
| 91 |
"metadata": {}, |
| 92 |
"outputs": [], |
| 93 |
"source": [ |
| 94 |
"import matplotlib.pyplot as plt\n", |
| 95 |
"\n", |
| 96 |
"\n", |
| 97 |
"fig, ax = plt.subplots()\n", |
| 98 |
"ax.scatter(df[\"a\"], df[\"b\"], c=df[\"b\"], s=3)" |
| 99 |
] |
| 100 |
}, |
| 101 |
{ |
| 102 |
"cell_type": "code", |
| 103 |
"execution_count": null, |
| 104 |
"metadata": {}, |
| 105 |
"outputs": [], |
| 106 |
"source": [ |
| 107 |
"rng = np.random.default_rng()\n", |
| 108 |
"data = rng.standard_normal((3, 100))\n", |
| 109 |
"fig, ax = plt.subplots()\n", |
| 110 |
"ax.scatter(data[0], data[1], c=data[2], s=3)" |
| 111 |
] |
| 112 |
}, |
| 113 |
{ |
| 114 |
"cell_type": "markdown", |
| 115 |
"metadata": {}, |
| 116 |
"source": [ |
| 117 |
"## Xarray\n", |
| 118 |
"\n", |
| 119 |
"Here we demonstrate `xarray` to ensure that it shows up properly." |
| 120 |
] |
| 121 |
}, |
| 122 |
{ |
| 123 |
"cell_type": "code", |
| 124 |
"execution_count": null, |
| 125 |
"metadata": {}, |
| 126 |
"outputs": [], |
| 127 |
"source": [ |
| 128 |
"import xarray as xr\n", |
| 129 |
"\n", |
| 130 |
"\n", |
| 131 |
"data = xr.DataArray(\n", |
| 132 |
" np.random.randn(2, 3), dims=(\"x\", \"y\"), coords={\"x\": [10, 20]}, attrs={\"foo\": \"bar\"}\n", |
| 133 |
")\n", |
| 134 |
"data" |
| 135 |
] |
| 136 |
}, |
| 137 |
{ |
| 138 |
"cell_type": "markdown", |
| 139 |
"metadata": {}, |
| 140 |
"source": [ |
| 141 |
"## ipyleaflet\n", |
| 142 |
"\n", |
| 143 |
"`ipyleaflet` is a **Jupyter**/**Leaflet** bridge enabling interactive maps in the Jupyter notebook environment. this demonstrate how you can integrate maps in your documentation." |
| 144 |
] |
| 145 |
}, |
| 146 |
{ |
| 147 |
"cell_type": "code", |
| 148 |
"execution_count": null, |
| 149 |
"metadata": {}, |
| 150 |
"outputs": [], |
| 151 |
"source": [ |
| 152 |
"from ipyleaflet import Map, basemaps\n", |
| 153 |
"\n", |
| 154 |
"\n", |
| 155 |
"# display a map centered on France\n", |
| 156 |
"m = Map(basemap=basemaps.Esri.WorldImagery, zoom=5, center=[46.21, 2.21])\n", |
| 157 |
"m" |
| 158 |
] |
| 159 |
} |
| 160 |
], |
| 161 |
"metadata": { |
| 162 |
"kernelspec": { |
| 163 |
"display_name": "Python 3", |
| 164 |
"language": "python", |
| 165 |
"name": "python3" |
| 166 |
}, |
| 167 |
"language_info": { |
| 168 |
"name": "python", |
| 169 |
"version": "3.11.6" |
| 170 |
} |
| 171 |
}, |
| 172 |
"nbformat": 4, |
| 173 |
"nbformat_minor": 2 |
| 174 |
} |