mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 08:50:39 +00:00
0b491c44166a73afc23434aea86a8bbdc45a321f
Added detailed instructions for invoking Python scripts via the startup wrapper in AGENTS.md. Updated repo-context.txt to reflect the inclusion of AGENTS.md and its contents, providing clarity on project structure and usage guidelines.
Lagged Oil–Unemployment Chart
A self-contained toolkit that:
- Fetches U.S. unemployment rate (UNRATE) and WTI crude oil price (DCOILWTICO) from FRED
- Stores the series in a local SQLite database (
data/fred.db) - Produces a dual-axis plot of unemployment vs. lagged oil price, with customizable lag, date range, and styling
🚀 Quickstart
# Clone the repo
git clone https://github.com/your-org/python_charts.git
cd python_charts
# One-command: install deps, download data, and plot
./startup.sh python scripts/lagged_oil_unrate_chart_styled.py \
--offset 12 --end 2025-05-31 --extend-years 5
This will:
- Create (or reuse) a Python 3 virtual environment (
venv/) - Upgrade
pip&setuptools(providingdistutilssupport) - Install required packages (offline wheelhouse first, PyPI fallback)
- Download UNRATE & DCOILWTICO into
data/fred.dbif missing - Generate the chart with a 12-month oil lead, extending the x-axis by 5 years
📁 Repository Structure
python_charts/
├── data/
│ └── fred.db # Local FRED snapshot (SQLite)
├── scripts/
│ ├── refresh_data.py # Download and store FRED series
│ ├── lagged_oil_unrate_chart_styled.py # Plotting script
│ └── pyproject.toml # Packaging metadata
├── startup.sh # Bootstraps venv, deps, data, and runs commands
├── requirements.txt # Python dependencies
└── README.md # This file
🛠️ Installation & Setup
-
Ensure you have Python 3.8+ installed on your system.
-
Clone and navigate into the project:
git clone https://github.com/your-org/python_charts.git cd python_charts -
Make the startup script executable:
chmod +x startup.sh
On first run,
startup.shwill build the environment, install dependencies, and pull data.
⚙️ Usage
Refresh FRED data
./startup.sh python scripts/refresh_data.py
Downloads the full UNRATE and WTI series (from 1948 to today) into data/fred.db.
Generate the chart
# Default 18-month lag
./startup.sh
# Custom lag, range, and extension
./startup.sh python scripts/lagged_oil_unrate_chart_styled.py \
--offset 6 --start 1980-01-01 --end 2025-05-31 --extend-years 2
| Option | Description |
|---|---|
--offset |
Lag in months (positive = oil leads; negative = oil lags) |
--start |
Start date (YYYY-MM-DD) |
--end |
End date (YYYY-MM-DD) |
--extend-years |
Years to extend the x-axis beyond the end date |
📝 Details
-
Data storage:
data/fred.db(SQLite) holds two tables:UNRATEandDCOILWTICO. -
Plot styling:
- Left y-axis: unemployment rate (%) from 3 to 15%, ticks every 2%.
- Right y-axis: log scale oil price (USD), doubling ticks from $3 upward.
- X-axis: years, major tick every 5 years, minor tick every year.
📦 Dependencies
Listed in requirements.txt:
pandas>=1.5.0
pandas_datareader>=0.10.0
matplotlib>=3.5.0
lxml>=4.6.0
python-dateutil>=2.8.1
startup.sh also upgrades pip & setuptools to ensure distutils is available.
🛡️ Troubleshooting
- ModuleNotFoundError: distutils: resolved automatically by upgrading
setuptoolsinstartup.sh. - Database not found: run
./startup.sh python scripts/refresh_data.pyto populatedata/fred.db. - Virtual-env issues: delete
venv/and re-runstartup.sh.
📄 License
This project is released under the MIT License. See LICENSE for details.
Languages
Python
95.5%
Shell
3.5%
Makefile
1%