Skip to content

Commit b21aedf

Browse files
committed
Add jupyter-dark-detect for automatic matplotlib dark mode theming.
Detects whether the browser is in dark mode via jupyter-dark-detect and sets the matplotlib style accordingly. Replaces hardcoded color constants in nvmath-python visualization cells with a COLOR1-COLOR6 palette that adapts to light/dark mode.
1 parent 1f614a8 commit b21aedf

34 files changed

+181
-106
lines changed

brev/entrypoint.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ if [ "$(id -u)" = "0" ]; then
6868
if [ ! -e "${HOME}/.ipython/profile_default/startup/00-add-cwd-to-path.py" ]; then
6969
gosu "${TARGET_USER}" ln -sf /accelerated-computing-hub/brev/ipython-startup-add-cwd-to-path.py "${HOME}/.ipython/profile_default/startup/00-add-cwd-to-path.py"
7070
fi
71-
7271
# Setup Git safe directory (run as target user)
7372
gosu "${TARGET_USER}" git config --global --add safe.directory "/accelerated-computing-hub" 2>/dev/null || true
7473

tutorials/accelerated-python/brev/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ scipy == 1.17.1
66
matplotlib == 3.10.8
77
opencv-python-headless == 4.13.0.92
88

9+
# Dark mode detection
10+
jupyter-dark-detect == 0.1.0
11+
912
# Jupyter
1013
jupyter == 1.1.1
1114
jupyter-server-proxy == 4.4.0

tutorials/accelerated-python/notebooks/fundamentals/02__numpy_linear_algebra__svd_reconstruction.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
"outputs": [],
2727
"source": [
2828
"import numpy as np\n",
29-
"import matplotlib.pyplot as plt\n",
3029
"import cv2\n",
3130
"import urllib.request\n",
32-
"import os"
31+
"import os\n",
32+
"from jupyter_dark_detect import is_dark\n",
33+
"import matplotlib.pyplot as plt\n",
34+
"plt.style.use('dark_background' if is_dark() else 'default')"
3335
]
3436
},
3537
{

tutorials/accelerated-python/notebooks/fundamentals/03__numpy_to_cupy__ndarray_basics.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"import numpy as np\n",
4242
"import cupy as cp\n",
4343
"import cupyx as cpx\n",
44+
"from jupyter_dark_detect import is_dark\n",
4445
"import matplotlib.pyplot as plt\n",
46+
"plt.style.use('dark_background' if is_dark() else 'default')\n",
4547
"\n",
4648
"# Helper to display benchmark results concisely.\n",
4749
"def print_benchmark(result):\n",

tutorials/accelerated-python/notebooks/fundamentals/04__numpy_to_cupy__svd_reconstruction.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
"outputs": [],
3131
"source": [
3232
"import numpy as xp\n",
33-
"import matplotlib.pyplot as plt\n",
3433
"import cv2\n",
35-
"import urllib.request"
34+
"import urllib.request\n",
35+
"from jupyter_dark_detect import is_dark\n",
36+
"import matplotlib.pyplot as plt\n",
37+
"plt.style.use('dark_background' if is_dark() else 'default')"
3638
]
3739
},
3840
{

tutorials/accelerated-python/notebooks/fundamentals/solutions/02__numpy_linear_algebra__svd_reconstruction__SOLUTION.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
"outputs": [],
2727
"source": [
2828
"import numpy as np\n",
29-
"import matplotlib.pyplot as plt\n",
3029
"import cv2\n",
3130
"import urllib.request\n",
32-
"import os"
31+
"import os\n",
32+
"from jupyter_dark_detect import is_dark\n",
33+
"import matplotlib.pyplot as plt\n",
34+
"plt.style.use('dark_background' if is_dark() else 'default')"
3335
]
3436
},
3537
{

tutorials/accelerated-python/notebooks/fundamentals/solutions/03__numpy_to_cupy__ndarray_basics__SOLUTION.ipynb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"import numpy as np\n",
5050
"import cupy as cp\n",
5151
"import cupyx as cpx\n",
52+
"from jupyter_dark_detect import is_dark\n",
5253
"import matplotlib.pyplot as plt\n",
54+
"plt.style.use('dark_background' if is_dark() else 'default')\n",
5355
"\n",
5456
"# Helper to display benchmark results concisely.\n",
5557
"def print_benchmark(result):\n",
@@ -888,8 +890,11 @@
888890
"# Plot 2: Speedup ratio\n",
889891
"speedups = [cpu / gpu for cpu, gpu in zip(cpu_times, gpu_times)]\n",
890892
"colors = ['green' if s > 1 else 'red' for s in speedups]\n",
891-
"ax2.bar(range(len(sizes)), speedups, color=colors, alpha=0.7, edgecolor='black')\n",
892-
"ax2.axhline(y=1.0, color='black', linestyle='--', linewidth=2, label='Break-even')\n",
893+
"_dark = is_dark()\n",
894+
"COLOR5 = \"#FFFFFF\" if _dark else \"#000000\"\n",
895+
"\n",
896+
"ax2.bar(range(len(sizes)), speedups, color=colors, alpha=0.7, edgecolor=COLOR5)\n",
897+
"ax2.axhline(y=1.0, color=COLOR5, linestyle='--', linewidth=2, label='Break-even')\n",
893898
"ax2.set_xticks(range(len(sizes)))\n",
894899
"ax2.set_xticklabels([f'{s:,}' for s in sizes], rotation=45, ha='right', fontsize=9)\n",
895900
"ax2.set_xlabel('Array Size (elements)', fontsize=12)\n",

tutorials/accelerated-python/notebooks/fundamentals/solutions/04__numpy_to_cupy__svd_reconstruction__SOLUTION.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
"outputs": [],
3131
"source": [
3232
"import cupy as xp\n",
33-
"import matplotlib.pyplot as plt\n",
3433
"import cv2\n",
35-
"import urllib.request"
34+
"import urllib.request\n",
35+
"from jupyter_dark_detect import is_dark\n",
36+
"import matplotlib.pyplot as plt\n",
37+
"plt.style.use('dark_background' if is_dark() else 'default')"
3638
]
3739
},
3840
{

tutorials/accelerated-python/notebooks/kernels/41__kernel_authoring__book_histogram.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
"\n",
5353
"import numpy as np\n",
5454
"import nsightful\n",
55+
"import urllib.request\n",
56+
"from jupyter_dark_detect import is_dark\n",
5557
"import matplotlib.pyplot as plt\n",
56-
"import urllib.request"
58+
"plt.style.use('dark_background' if is_dark() else 'default')"
5759
]
5860
},
5961
{

tutorials/accelerated-python/notebooks/kernels/42__kernel_authoring__gaussian_blur.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
" open(\"/accelerated-computing-hub-installed\", \"a\").close()\n",
3131
" print(\"All packages installed.\")\n",
3232
"\n",
33-
"import matplotlib as mpl\n",
34-
"import matplotlib.pyplot as plt\n",
3533
"from numba import cuda\n",
3634
"import numpy as np\n",
3735
"import math\n",
3836
"import urllib.request\n",
3937
"import cv2\n",
38+
"from jupyter_dark_detect import is_dark\n",
39+
"import matplotlib.pyplot as plt\n",
40+
"plt.style.use('dark_background' if is_dark() else 'default')\n",
4041
"\n",
4142
"plt.rcParams[\"figure.figsize\"] = (30, 4)"
4243
]

0 commit comments

Comments
 (0)