This repository contains a submission for the 2025 Plotnine Contest. The Jupyter notebook retrieves and analyses MOT (Ministry of Transport) test history for a specified vehicle using the DVSA (Driver and Vehicle Standards Agency) MOT History API. It produces an adaptive two-part visualisation:
- A mileage plot showing the vehicle's odometer readings over time.
- A fault plot displaying the number and severity of faults recorded during MOT tests.
This visualisation is exported into the outputs/ folder.
You can either query the official DVSA MOT History API (requires credentials) or re-run the notebook using the included example JSON files in data/.
I created this project to:
- Improve my knowledge of Python and use Plotnine for the first time (frequent R user).
- Develop a tool to better visualise vehicle history (the UK GOV MOT checker can be intimidating).
.
βββ code.ipynb # Main Jupyter Notebook with the full analysis + plotting workflow
βββ data/ # Example JSON files for 5 vehicles from DVSA MOT history lookups
βββ outputs/ # Generated visualisations (saved as PNG files)
βββ README.md # This file
Note: The examples in
data/areMW02WVU.json,SK05HZC.json,YE55XSR.json,OY15CGK.json,MF68CZR.json, andoutputs/contains visualisations generated for these vehicles.
- Data extraction β either requests MOT history from the DVSA MOT History API or loads a local example JSON from
data/. - Processing β normalises and flattens returned JSON structures into a tidy
pandas.DataFrameof MOT tests (date, odometer, faults, test result, etc.). - Visualisation β builds two plotnine plots:
- Mileage plot β shows recorded odometer readings / mileage across MOT tests.
- Fault plot β visualises the number and severity/type of faults recorded across tests.
- Combined figure β stacks the two plots and saves a high-resolution PNG to
outputs/{registration}.png.
The notebook imports and uses the following Python packages:
plotninemizanipandasnumpyrequestsjsondatetime
- Put one of the example JSON files into the
data/directory (or confirm the included files are present). - Open the notebook:
- In the data extraction and processing cells, run cell 3 (and not cell 2), which loads a local JSON file (the notebook includes a prompt that asks for a filename β enter e.g.
MW02WVU.json). Run the notebook cells in order. - After the cells run, the final plot will be saved to
outputs/{registration}.pngand the plot object displayed in the notebook.
If you prefer to fetch live data from the DVSA MOT History API, do the following:
- Register for access to the DVSA MOT History API and obtain the required credentials (
https://documentation.history.mot.api.gov.uk/). - In the notebook, set the following variables (or modify the notebook to read them from environment variables):
VEHICLE_REGISTRATION = "YOUR_REGISTRATION"
CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"
API_KEY = "YOUR_API_KEY"
TOKEN_URL = "https://..." # as required by the DVSA OAuth2 endpoint
SCOPE = "..." # if required- Run cell 2 (and not cell 3), which will obtain an access token and call the API. The notebook contains helper functions to request an OAuth2 token and then retrieve vehicle history from the endpoint.
- Proceed to the plotting cells β the notebook will save the final plot under
outputs/{registration}.png.
-
Saved plot path format:
outputs/{registration}.png(high-resolution PNG). -
The notebook automatically creates
outputs/if it does not exist. -
plotnine&mizanifor the plotting grammar and scales -
pandasfor data processing