Modular matplotlib plotting helpers
Project description
Matplot Flex
モジュール化されたサブプロット構成、テキストのフィット、基本レンダラーをまとめた Matplotlib 補助ライブラリです。
インストール(PyPI)
pip install matplot-flex
未公開の場合は GitHub から直接インストールできます。
pip install "matplot-flex @ git+https://github.com/obitsu-jo/matplot-flex.git"
対応環境
- Python 3.10 以上
クイックスタート
import numpy as np
from matplot_flex import (
AxisConfig, LegendConfig, LegendItem, SeriesSpec,
plot_template, divide_fig_ratio, draw_graph_module, plot_on_module,
render_line, render_multi,
)
fig, figs = plot_template("My Plot")
left_fig, right_fig = divide_fig_ratio(figs[1], "horizontal", ratios=[1, 1])
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
series = [
SeriesSpec(x=x, y=y1, renderer=render_line, label="sin"),
SeriesSpec(x=x, y=y2, renderer=render_line, label="cos", linestyle="--"),
]
legend_items = [
LegendItem(label="sin", color="tab:blue"),
LegendItem(label="cos", color="tab:orange", linestyle="--"),
]
module = draw_graph_module(left_fig)
plot_on_module(
module,
x,
y1,
"Sine & Cosine",
renderer=lambda ax, xx, yy: render_multi(ax, series),
x_axis=AxisConfig(label="x"),
y_axis=AxisConfig(label="value"),
legend=LegendConfig(items=legend_items, position="upper center", offset=(0.0, 0.02)),
series_specs=series, # ensures axes cover all series
)
fig.savefig("example.png", dpi=220)
構成
matplot_flex/config.py: 軸/凡例/グリッド設定(AxisConfig.padによる余白指定を含む)。matplot_flex/axes_utils.py: Figure/SubFigure の主Axes取得ヘルパ。matplot_flex/text_utils.py: テキストフィット、パラメータ整形、角丸フレーム(zorder指定)、日付/指数フォーマッタ。matplot_flex/renderers.py: 折れ線/散布/棒グラフ、複数系列補助、SeriesSpec。matplot_flex/layout.py: Figure/SubFigure 生成と分割ユーティリティ。matplot_flex/decorators.py: 目盛/ラベル/グリッドなどの装飾処理。matplot_flex/templates.py:plot_template/plot_on_moduleの合成処理。main.py:modular_subplot_example.pngを生成するサンプル。smoke_test.py: 生成確認の簡易テスト。
公開APIは matplot_flex/__init__.py から再エクスポートしています。
詳細なAPIノートは matplot_flex/README.md、完全仕様は docs/full_reference.md を参照してください。
サンプルの実行
python main.py
リポジトリ直下に modular_subplot_example.png を出力します。
CI
GitHub Actions で python smoke_test.py を実行します。
テスト
python smoke_test.py
PNG を再生成して、生成できたことを確認します。
python -m pytest -q
代表的な利用パターンの描画が通ることを確認します。
依存関係の方針
ライブラリ利用向けの範囲指定は pyproject.toml で管理し、開発・CI の再現性は requirements.txt の固定版で担保します。
開発環境の導入:
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
pip install -e .
バージョニング方針
SemVer(MAJOR.MINOR.PATCH)に従います。変更履歴は CHANGELOG.md を参照してください。
- MAJOR: 互換性のない変更
- MINOR: 後方互換のある機能追加
- PATCH: 後方互換のあるバグ修正
ローカルパッケージとして導入(再利用向け)
pip install -e .
以降は同一環境の別ディレクトリから import matplot_flex できます。
PyPI 公開手順
- PyPI のアカウント作成と 2FA 設定
pyproject.tomlのversionを更新- 配布物を作成
python -m build
- PyPI にアップロード
python -m twine upload dist/*
更新手順(リリース)
- 変更を反映
pyproject.tomlのversionを更新CHANGELOG.mdに変更内容を追記- テストを実行
python -m pytest -q
- ビルドとアップロード
rm -rf dist/
python -m build
python -m twine upload dist/*
- 任意でタグを付ける
git tag vX.Y.Z
git push origin vX.Y.Z
ライセンス
MIT License(LICENSE を参照)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matplot_flex-0.2.0.tar.gz.
File metadata
- Download URL: matplot_flex-0.2.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cb287110fb6b832ffbb04f97cde79549e29b97f13dd2a17db704ffaa38a2366
|
|
| MD5 |
23a8687d8e83dc80eea8f4d47415f07c
|
|
| BLAKE2b-256 |
ee63fad894a282e2467e87eb607e764c6832176d98158561a8b4e08dd45ca352
|
File details
Details for the file matplot_flex-0.2.0-py3-none-any.whl.
File metadata
- Download URL: matplot_flex-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e61034a16c422e48deb72b32b51347fb443614bb08be2d30c98a4a5b1cc3c61e
|
|
| MD5 |
6af42291cfa614a50a8d664832c15d6d
|
|
| BLAKE2b-256 |
a200e2d8d0053fcd2b3a33a64c13050f73830fc684c5cf6f412b154cb9ceabfd
|