Created
November 7, 2025 16:06
-
-
Save barronh/5fdc1e06c4f30229e156963a277c38c3 to your computer and use it in GitHub Desktop.
matplotlib aqi colorscale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_epacmapnorm(spc, freq): | |
| """ | |
| Arguments | |
| --------- | |
| spc : str | |
| choices 'pm25' or 'o3' | |
| freq : str | |
| choices '1h', '24h' (pm-only), '8h' (o3-only), 'mda8' (o3-only) | |
| Returns | |
| ------- | |
| cmap, norm : matplotlib.colormaps.Colormap, matplotlib.colors.BoundaryNorm | |
| Notes | |
| ----- | |
| Colors for 24h and 8h are EPA AQI. For 1h, the colors are consistent with EPA's airnowtech | |
| AQI colors and cutpoints are consistent with EPA-454/B-24-002 May 2024 | |
| """ | |
| import matplotlib.colors as mc | |
| aqicolors = ['#00e300', '#fefe00', '#fe7e00', '#fe0000', '#8e3f96', '#7e0023'] | |
| pm1hcolors = [ | |
| '#009500', '#98cb00', '#fefe98', '#fefe00', | |
| '#fecb00', '#f69800', '#fe0000', '#d50092' | |
| ] # 8 colors between 9 edges | |
| pm1hedges = [-5, 10, 20, 30, 50, 70, 90, 120, 1000] | |
| # pm24hedges = [0, 12, 35.5, 55.5, 150.5, 250.5, 255] # old pm25 aqi cutpoints EPA 454/B-18-007 September 2018 | |
| pm24hedges = [0, 9, 35.5, 55.5, 125.5, 225.5, 255] # new pm25 aqi cutpoints EPA-454/B-24-002 May 2024 | |
| o31hcolors = [ | |
| '#00fe00', '#fefe80', '#fefe00', '#fbbe43', '#fe8000', '#fe0000' | |
| ] # 6 colors beteen 7 edges for airnowtech 1h | |
| o31hedges = [0, 60, 80, 100, 112, 125, 1000] # airnowtech 1h cuts | |
| o3mda8edges = [0, 54, 70, 85, 105, 200, 255] # ozone ppb aqi cutpoints EPA-454/B-24-002 May 2024 | |
| levels, colors = { | |
| ('pm25', '1h'): (pm1hedges, pm1hcolors), | |
| ('pm25', '24h'): (pm24hedges, aqicolors), | |
| ('o3', '1h'): (o31hedges, o31hcolors), | |
| ('o3', '8h'): (o3mda8edges, aqicolors), | |
| ('o3', 'mda8'): (o3mda8edges, aqicolors), | |
| }[spc, freq] | |
| return mc.from_levels_and_colors(levels, colors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment