# Chapter 10 MATLAB-to-Python conversions

This folder contains literal Python conversions of the supplied MATLAB files. Variable names, comments, plot colors, line styles, line widths, marker sizes, axis limits, ticks, and labels have been retained wherever Python permits.

Every explicitly specified MATLAB font size was reduced by 2 points. Fixed MATLAB desktop-window positions were replaced by portable Matplotlib `figsize` settings so the figures fit normally in a Python plot window.

## Converted files

| MATLAB source | Python conversion |
|---|---|
| `fig10_15(5).m` | `fig10_15.py` |
| `fig10_18(5).m` | `fig10_18.py` |
| `fig10_19(2).m` | `fig10_19.py` |
| `fig10_20(5).m` | `fig10_20.py` |
| `fig10_21(2).m` | `fig10_21.py` |
| `fig10_22(3).m` | `fig10_22.py` |
| `fig10_23(5).m` | `fig10_23.py` |
| `table10_6(5).m` | `table10_6.py` |
| `parseArgs(3).m` | `parseArgs.py` |
| `subaxis(3).m` | `subaxis.py` |

The uploaded data and image files are included under the filenames expected by the converted programs:

- `covid_data.txt`
- `covid_data2.txt`
- `covid_data3.txt`
- `crime_data_2009.txt`
- `flowers.jpg`
- `fox2.jpg`

`covid_data2.txt` and `crime_data_2009.txt` are included for completeness, although none of the supplied MATLAB programs refers to them directly.

## Installation

From Terminal, change to this folder and create an optional virtual environment:

```bash
cd chapter10_python_conversions
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
```

## Running the programs

Run a figure program with, for example:

```bash
python3 fig10_18.py
```

Run the table program with:

```bash
python3 table10_6.py
```

Each file also defines a function with the same base name, so it can be imported:

```python
from fig10_20 import fig10_20

fig10_20()
```

## Conversion notes

- MATLAB's 1-based indexing is translated to Python's 0-based indexing. County numbers such as `r1 = 1`, `r2 = 15`, and `r3 = 56` are retained, with a separate zero-based index used when accessing arrays.
- `subaxis.py` and `parseArgs.py` reproduce the supplied helper functions and their abbreviated named options (`MT`, `MB`, `MR`, `ML`, `P`, and related forms).
- `fig10_15.py` retains the same fourth-moment/kurtosis calculation. Its repeated full-image loop was replaced by the algebraically identical fourth-moment expansion so it runs in seconds rather than repeatedly constructing large images for all 1,440 angles.
- The active MATLAB `exportgraphics` command in `fig10_18.m` is converted to save `covid.eps` in this folder rather than to the original hard-coded `/Users/mark/Desktop` location.
- `fig10_23.py` requires the New York GIS shapefile referenced by the MATLAB program. Place `Counties_Shoreline.shp` and its companion `.shx` and `.dbf` files in this folder before running it. Those GIS files were not among the uploaded files, so they are not included here.
