- Version: 20261019
- Source Code Copyright: Unknown
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Minimal console/terminal sample for plotting stock OHLC data with matplotlib, supporting Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon). The script reads a CSV with a date column plus open/high/low/close price columns, draws all four price lines over the date axis, and saves the chart as a PNG (optionally also showing it in a window). The example dataset is 678 daily rows (2017–2019). CPU only: pandas and matplotlib have no GPU backend (no CUDA, no Apple GPU), and one chart takes about a second.
[Folder Structure]
- CLAUDE.md / AGENTS.md: Program specification (identical content).
- CHANGELOG.md: Change log.
- copyright.txt: Copyright notice.
- Data-Matplot-Stock-Python.html: This document (usage page).
- data/stock/stock-data.csv: date,volume,open,high,low,close (678 daily rows).
- model/stock/stock_plot.png: Written by src/plot.py.
- tool/tools.py: Shared helpers: project_root, delete_ipynb_checkpoints.
- src/: Source code and launcher scripts.
- venv/: Python virtual environment, created by 02_venv_create_windows/linux/mac.
[Prerequisites]
- Python 3.14, installed by 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh (Windows: winget; Ubuntu: apt, or the deadsnakes PPA when the Ubuntu archive has no python3.14; macOS: Homebrew).
- 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh create venv/ with Python 3.14 and install pandas and matplotlib from src/requirements.txt (same packages on every OS).
- GPU: none. CPU only on every OS, because pandas and matplotlib have no GPU backend; no NVIDIA driver or CUDA is needed.
- --show needs a desktop session (Windows and Ubuntu: Tk window, tkinter is part of the Python that 01_python_install_{os} installs; on Ubuntu, if Python 3.14 was already installed before, add it with sudo apt-get install python3.14-tk, otherwise matplotlib falls back to Agg and no window opens; macOS: matplotlib's native macosx window).
[Launcher Scripts]
1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh
Install Python 3.14 (winget / apt or deadsnakes PPA, needs sudo / Homebrew). Skips the install when Python 3.14 is already present. On Windows, open a new terminal afterwards.
2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh
Delete the old venv/, create a fresh one with Python 3.14, install src/requirements.txt. Aborts loudly if pip fails.
3. 03_venv_activate.bat / 03_venv_activate.sh
Activate the venv. On Linux/macOS, source it: source src/03_venv_activate.sh (bash or zsh). If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.
4. 04_plot.bat / 04_plot.sh
Draw the OHLC chart and save it to model/stock/stock_plot.png. Extra args are forwarded to plot.py.
5. 99_venv_clean.bat / 99_venv_clean.sh
Delete the venv/ folder.
6. 99_venv_deactivate.bat / 99_venv_deactivate.sh
Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).
[Python Entry Point]
src/plot.py
--input data/stock/stock-data.csv --output model/stock/stock_plot.png [--show]. Without --show the chart is only saved (Agg backend — works headless); with --show it also opens a window. Dates are parsed flexibly (2017/01/04-style and ISO both work). Runs on the CPU (pandas and matplotlib have no GPU backend); there is no --device option.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
REM open a new terminal
src\02_venv_create_windows.bat
src\04_plot.bat
Ubuntu 24.04
bash src/01_python_install_linux.sh
bash src/02_venv_create_linux.sh
bash src/04_plot.sh
macOS 14+ (Apple Silicon)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/04_plot.sh
Add --show to also display the chart. Point --input at your own CSV (same column names) to plot other stocks.
[Data Format]
- CSV with a header row and columns date, open, high, low, close (extra columns such as volume are ignored by the plot).
- The date column may use YYYY/MM/DD or ISO format.
[References]
- matplotlib: https://matplotlib.org/stable/
- pandas documentation: https://pandas.pydata.org/docs/
This SDK is built in AppForAI - AI Dev Tools.