Skip to content

Commit adeaa1f

Browse files
authored
Merge pull request #17 from sbu-python-class/alt-text
work of matplotlib alt-text
2 parents e97a05a + 2712660 commit adeaa1f

File tree

13 files changed

+208
-134
lines changed

13 files changed

+208
-134
lines changed

.github/workflows/docs-test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Doc test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
doc-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v6
20+
with:
21+
python-version: "3.14"
22+
cache: "pip"
23+
24+
- name: Install Python dependencies
25+
run: |
26+
sudo apt-get install python3-pip graphviz
27+
pip install -r requirements.txt
28+
pip install ghp-import
29+
PATH="${PATH}:${HOME}/.local/bin"
30+
31+
- name: Build book HTML
32+
run: |
33+
./build_and_process.sh

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v6
14+
1415
- name: Set up Python
1516
uses: actions/setup-python@v6
1617
with:
1718
python-version: "3.14"
1819
cache: "pip"
20+
1921
- name: Install Python dependencies
2022
run: |
2123
sudo apt-get install python3-pip graphviz
@@ -25,7 +27,7 @@ jobs:
2527
2628
- name: Build book HTML
2729
run: |
28-
KERAS_BACKEND="torch" jupyter-book build ./content
30+
./build_and_process.sh
2931
3032
- name: Push _build/html to gh-pages
3133
run: |

build_and_process.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
KERAS_BACKEND="torch" jupyter-book build content
4+
5+
cd content/_build/html
6+
for i in $(grep -lR "# alt-text" | grep html)
7+
do
8+
echo $i
9+
../../../parse_alt.py $i
10+
done

content/02-numpy/numpy-basics.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@
576576
"\n",
577577
"Multidimensional arrays are stored in a contiguous space in memory -- this means that the columns / rows need to be unraveled (flattened) so that it can be thought of as a single one-dimensional array. Different programming languages do this via different conventions:\n",
578578
"\n",
579-
"![](row_column_major.png)\n",
579+
"![multidimensional array formatting, row-major vs. column-major](row_column_major.png)\n",
580580
"\n",
581581
"Storage order:\n",
582582
"\n",
@@ -780,7 +780,7 @@
780780
"name": "python",
781781
"nbconvert_exporter": "python",
782782
"pygments_lexer": "ipython3",
783-
"version": "3.13.2"
783+
"version": "3.14.2"
784784
}
785785
},
786786
"nbformat": 4,

content/04-matplotlib/matplotlib-basics.ipynb

Lines changed: 31 additions & 85 deletions
Large diffs are not rendered by default.

content/04-matplotlib/matplotlib-exercises.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@
286286
],
287287
"source": [
288288
"fig, ax = plt.subplots()\n",
289-
"ax.imshow(m)"
289+
"ax.imshow(m)\n",
290+
"# alt-text: a plot of the Mandelbrot set"
290291
]
291292
},
292293
{
@@ -313,7 +314,7 @@
313314
"name": "python",
314315
"nbconvert_exporter": "python",
315316
"pygments_lexer": "ipython3",
316-
"version": "3.12.3"
317+
"version": "3.14.2"
317318
}
318319
},
319320
"nbformat": 4,

content/05-scipy/scipy-basics-2.ipynb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
"source": [
126126
"fig, ax = plt.subplots()\n",
127127
"ax.scatter(x,y)\n",
128-
"ax.errorbar(x, y, yerr=sigma, fmt=\"o\")"
128+
"ax.errorbar(x, y, yerr=sigma, fmt=\"o\")\n",
129+
"# alt-text: a plot showing data points with vertical error bars"
129130
]
130131
},
131132
{
@@ -214,7 +215,8 @@
214215
],
215216
"source": [
216217
"ax.plot(x, afit[0] + afit[1]*x + afit[2]*x*x )\n",
217-
"fig"
218+
"fig\n",
219+
"# alt-text: a plot showing data points with error bars and a quadratic fit to them"
218220
]
219221
},
220222
{
@@ -320,7 +322,8 @@
320322
"source": [
321323
"fig, ax = plt.subplots()\n",
322324
"ax.scatter(x,y)\n",
323-
"ax.errorbar(x, y, yerr=sigma, fmt=\"o\", label=\"_nolegend_\")"
325+
"ax.errorbar(x, y, yerr=sigma, fmt=\"o\", label=\"_nolegend_\")\n",
326+
"# alt-text: a plot showing a noisy exponential dataset with error bars"
324327
]
325328
},
326329
{
@@ -402,7 +405,8 @@
402405
" label=r\"$a_0 = $ %f; $a_1 = $ %f\" % (afit[0], afit[1]))\n",
403406
"ax.plot(x, a0_orig*np.exp(a1_orig*x), \":\", label=\"original function\")\n",
404407
"ax.legend(numpoints=1, frameon=False)\n",
405-
"fig"
408+
"fig\n",
409+
"# alt-text: a plot showing noisy exponential data points, a fit, and the original function"
406410
]
407411
},
408412
{
@@ -589,7 +593,8 @@
589593
"source": [
590594
"npts = 128\n",
591595
"xx, f = single_freq_sine(npts)\n",
592-
"plot_FFT(xx, f)"
596+
"plot_FFT(xx, f)\n",
597+
"# alt-text: a plot with 4 vertical panels showing (1) a sine (2) the Fourier transform of the sine (3) the power in Fourier space (4) the data transformed back to real space"
593598
]
594599
},
595600
{
@@ -645,7 +650,8 @@
645650
],
646651
"source": [
647652
"xx, f = single_freq_cosine(npts)\n",
648-
"plot_FFT(xx, f)"
653+
"plot_FFT(xx, f)\n",
654+
"# alt-text: a plot with 4 vertical panes showing a single-mode cosine transformed to Fourier space and back"
649655
]
650656
},
651657
{
@@ -701,7 +707,8 @@
701707
],
702708
"source": [
703709
"xx, f = single_freq_sine_plus_shift(npts)\n",
704-
"plot_FFT(xx, f)"
710+
"plot_FFT(xx, f)\n",
711+
"# alt-text: a plot with 4 vertical panes showing a single-mode sine with a phase shift transformed to Fourier space and back"
705712
]
706713
},
707714
{
@@ -782,7 +789,8 @@
782789
"xx, f = two_freq_sine(npts)\n",
783790
"\n",
784791
"fig, ax = plt.subplots()\n",
785-
"ax.plot(xx, f)"
792+
"ax.plot(xx, f)\n",
793+
"# alt-text: a plot showing a two-mode sine wave"
786794
]
787795
},
788796
{
@@ -847,7 +855,8 @@
847855
"fig, ax = plt.subplots()\n",
848856
"ax.plot(kfreq, fk.real, label=\"real\")\n",
849857
"ax.plot(kfreq, fk.imag, \":\", label=\"imaginary\")\n",
850-
"ax.legend(frameon=False)"
858+
"ax.legend(frameon=False)\n",
859+
"# alt-text: the FFT of our two-mode sine-wave showing two spikes"
851860
]
852861
},
853862
{
@@ -915,7 +924,8 @@
915924
],
916925
"source": [
917926
"fig, ax = plt.subplots()\n",
918-
"ax.plot(xx, fkinv.real)"
927+
"ax.plot(xx, fkinv.real)\n",
928+
"# alt-text: a plot of a single-mode sine wave"
919929
]
920930
},
921931
{
@@ -1278,7 +1288,8 @@
12781288
],
12791289
"source": [
12801290
"fig, ax = plt.subplots()\n",
1281-
"ax.plot(x[1:N-1], sol)"
1291+
"ax.plot(x[1:N-1], sol)\n",
1292+
"# alt-text: a plot showing a function that looks approximately like -sin(x)"
12821293
]
12831294
},
12841295
{
@@ -1305,7 +1316,7 @@
13051316
"name": "python",
13061317
"nbconvert_exporter": "python",
13071318
"pygments_lexer": "ipython3",
1308-
"version": "3.13.2"
1319+
"version": "3.14.2"
13091320
}
13101321
},
13111322
"nbformat": 4,

content/05-scipy/scipy-basics.ipynb

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@
538538
"x_fine = np.linspace(0, 20, 10*N)\n",
539539
"\n",
540540
"ax.scatter(x, y)\n",
541-
"ax.plot(x_fine, f_exact(x_fine), ls=\":\", label=\"original function\")"
541+
"ax.plot(x_fine, f_exact(x_fine), ls=\":\", label=\"original function\")\n",
542+
"# alt-text: a figure showing data points and an interpolant passing through them"
542543
]
543544
},
544545
{
@@ -578,7 +579,8 @@
578579
"ax.plot(x_fine, f_interp(x_fine), label=\"interpolant\")\n",
579580
"\n",
580581
"ax.legend(frameon=False, loc=\"best\")\n",
581-
"fig"
582+
"fig\n",
583+
"# alt-text: a figure showing data points, an interpolant to them, and the original function we sampled"
582584
]
583585
},
584586
{
@@ -666,7 +668,8 @@
666668
"fig, ax = plt.subplots()\n",
667669
"data = func(x, y)\n",
668670
"im = ax.imshow(data.T, extent=(0, 1, 0, 1), origin=\"lower\")\n",
669-
"fig.colorbar(im, ax=ax)"
671+
"fig.colorbar(im, ax=ax)\n",
672+
"# alt-text: a heat-map figure showing a function with small-amplitude ripples"
670673
]
671674
},
672675
{
@@ -714,7 +717,8 @@
714717
"source": [
715718
"fig, ax = plt.subplots()\n",
716719
"im = ax.imshow(coarse.T, extent=(0, 1, 0, 1), origin=\"lower\")\n",
717-
"fig.colorbar(im, ax=ax)"
720+
"fig.colorbar(im, ax=ax)\n",
721+
"# alt-text: a heat-map showing coarsened representation of our function"
718722
]
719723
},
720724
{
@@ -820,7 +824,8 @@
820824
"source": [
821825
"fig, ax = plt.subplots()\n",
822826
"im = ax.imshow(new_data.T, extent=(0, 1, 0, 1), origin=\"lower\")\n",
823-
"fig.colorbar(im, ax=ax)"
827+
"fig.colorbar(im, ax=ax)\n",
828+
"# alt-text: a heat-map showing the reconstructed function via interpolation"
824829
]
825830
},
826831
{
@@ -860,7 +865,8 @@
860865
"diff = new_data - data\n",
861866
"fig, ax = plt.subplots()\n",
862867
"im = ax.imshow(diff.T, origin=\"lower\", extent=(0, 1, 0, 1))\n",
863-
"fig.colorbar(im, ax=ax)"
868+
"fig.colorbar(im, ax=ax)\n",
869+
"# alt-text: a heat-map showing the error in our interpolation. It is better than 10%"
864870
]
865871
},
866872
{
@@ -964,7 +970,8 @@
964970
"fig, ax = plt.subplots()\n",
965971
"ax.plot(x, f(x))\n",
966972
"ax.scatter(np.array([root]), np.array([f(root)]))\n",
967-
"ax.grid()"
973+
"ax.grid()\n",
974+
"# alt-text: a plot of our function with the root represented as a point"
968975
]
969976
},
970977
{
@@ -1104,7 +1111,8 @@
11041111
"fig = plt.figure()\n",
11051112
"ax = plt.axes(projection='3d')\n",
11061113
"ax.plot(X[0,:], X[1,:], X[2,:])\n",
1107-
"fig.set_size_inches(8.0,6.0)"
1114+
"fig.set_size_inches(8.0,6.0)\n",
1115+
"# alt-text: a 3D line plot of the solution -- it is dominated by two lobe-like structures"
11081116
]
11091117
},
11101118
{
@@ -1192,13 +1200,14 @@
11921200
"\n",
11931201
"ax.plot(X[0,:], X[1,:], X[2,:])\n",
11941202
"\n",
1195-
"ax.scatter(sol1.x[0], sol1.x[1], sol1.x[2], marker=\"x\", color=\"r\")\n",
1196-
"ax.scatter(sol2.x[0], sol2.x[1], sol2.x[2], marker=\"x\", color=\"r\")\n",
1197-
"ax.scatter(sol3.x[0], sol3.x[1], sol3.x[2], marker=\"x\", color=\"r\")\n",
1203+
"ax.scatter(sol1.x[0], sol1.x[1], sol1.x[2], marker=\"x\", color=\"C1\")\n",
1204+
"ax.scatter(sol2.x[0], sol2.x[1], sol2.x[2], marker=\"x\", color=\"C1\")\n",
1205+
"ax.scatter(sol3.x[0], sol3.x[1], sol3.x[2], marker=\"x\", color=\"C1\")\n",
11981206
"\n",
11991207
"ax.set_xlabel(\"x\")\n",
12001208
"ax.set_ylabel(\"y\")\n",
1201-
"ax.set_zlabel(\"z\")"
1209+
"ax.set_zlabel(\"z\")\n",
1210+
"# alt-text: the 3D solution again represented as a line / trajectory, now with the stable-points marked"
12021211
]
12031212
},
12041213
{
@@ -1342,7 +1351,8 @@
13421351
"ax.loglog(ts, Ys[2,:], label=r\"$y_3$\")\n",
13431352
"\n",
13441353
"ax.legend(loc=\"best\", frameon=False)\n",
1345-
"ax.set_xlabel(\"time\")"
1354+
"ax.set_xlabel(\"time\")\n",
1355+
"# alt-text: the time-evolution of the species on a log scale"
13461356
]
13471357
},
13481358
{
@@ -1373,7 +1383,7 @@
13731383
"name": "python",
13741384
"nbconvert_exporter": "python",
13751385
"pygments_lexer": "ipython3",
1376-
"version": "3.13.3"
1386+
"version": "3.14.2"
13771387
}
13781388
},
13791389
"nbformat": 4,

content/05-scipy/scipy-exercises-2.ipynb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"cells": [
33
{
4-
"cell_type": "code",
5-
"execution_count": 1,
4+
"cell_type": "markdown",
65
"metadata": {},
7-
"outputs": [],
86
"source": [
9-
"import numpy as np\n",
10-
"import matplotlib.pyplot as plt"
7+
"# More SciPy Exercises"
118
]
129
},
1310
{
14-
"cell_type": "markdown",
11+
"cell_type": "code",
12+
"execution_count": 1,
1513
"metadata": {},
14+
"outputs": [],
1615
"source": [
17-
"# More SciPy Exercises"
16+
"import numpy as np\n",
17+
"import matplotlib.pyplot as plt"
1818
]
1919
},
2020
{
@@ -176,7 +176,8 @@
176176
],
177177
"source": [
178178
"plt.plot(x, noisy)\n",
179-
"plt.plot(x, orig)"
179+
"plt.plot(x, orig)\n",
180+
"# alt-text: a plot showing noisy sinusoidal and the original, un-noised data"
180181
]
181182
},
182183
{
@@ -299,7 +300,8 @@
299300
"source": [
300301
"plt.plot(t, restrict_theta(y[0,:]))\n",
301302
"plt.xlabel(\"t\")\n",
302-
"plt.ylabel(r\"$\\theta$\")"
303+
"plt.ylabel(r\"$\\theta$\")\n",
304+
"# alt-text: a plot showing many periods of a sinusoidal function"
303305
]
304306
},
305307
{
@@ -367,7 +369,7 @@
367369
"name": "python",
368370
"nbconvert_exporter": "python",
369371
"pygments_lexer": "ipython3",
370-
"version": "3.13.2"
372+
"version": "3.14.2"
371373
}
372374
},
373375
"nbformat": 4,

0 commit comments

Comments
 (0)