Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install ".[test]"
pip install ".[dev]"

- name: Inspect maxplotlib arguments
run: |
Expand All @@ -38,3 +38,7 @@ jobs:
run: |
coverage run -m pytest .
coverage report --sort=cover

- name: Test tutorials
run: |
jupyter nbconvert --to notebook --execute tutorials/*.ipynb --output-dir=/tmp --ExecutePreprocessor.timeout=300
53 changes: 53 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy docs to GitHub Pages

on:
push:
branches: ["devel", "main"] # TODO: Set to main only after release
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pandoc
run: |
sudo apt-get update
sudo apt-get install -y pandoc

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install ".[docs]"

- name: Build Sphinx docs
run: |
cd docs
make html

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload built docs
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 # Use the latest stable version
hooks:
- id: check-added-large-files # Prevent giant files from being committed.
args: ["--maxkb=1000"]
- id: check-merge-conflict # Check for files that contain merge conflict strings.
- id: check-toml # Attempts to load all TOML files to verify syntax.
- id: check-yaml # Attempts to load all yaml files to verify syntax.
args: ["--unsafe"]

- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout # remove jupyter notebook cell output
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
49 changes: 49 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import shutil


def copy_tutorials(app):
src = os.path.abspath("../tutorials")
dst = os.path.abspath("source/tutorials")

# Remove existing target directory if it exists
if os.path.exists(dst):
shutil.rmtree(dst)

shutil.copytree(src, dst)


def setup(app):
app.connect("builder-inited", copy_tutorials)


# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "maxplotlib"
copyright = "2025, Max Lindqvist"
author = "Max Lindqvist"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"nbsphinx",
"sphinx.ext.mathjax",
"sphinx.ext.autodoc",
]

templates_path = ["_templates"]
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
23 changes: 23 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. maxplotlib documentation master file, created by
sphinx-quickstart on Sun Jun 22 11:14:00 2025.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

maxplotlib documentation
========================

Add your content using ``reStructuredText`` syntax. See the
`reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
documentation for details.


.. toctree::
:maxdepth: 2
:caption: Tutorials:

tutorials/tutorial_01
tutorials/tutorial_02
tutorials/tutorial_03
tutorials/tutorial_04
tutorials/tutorial_05
tutorials/tutorial_06
13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ test = [
"pytest",
"coverage",
]
docs = [
"myst-parser",
"sphinx",
"sphinx-rtd-theme",
"nbsphinx",
"ipykernel",
"nbconvert",
]
dev = [
"maxplotlib[test]",
"maxplotlib[test,docs]",
"ruff",
"black",
"isort",
"jupyterlab",
"nbstripout",
"pre-commit",
"pyproject-fmt",
]
[project.urls]
"Source" = "https://github.com/max-models/maxplotlib"
Expand Down
1 change: 1 addition & 0 deletions src/maxplotlib/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):

for (row, col), subplot in self.subplots.items():
ax = axes[row][col]
# print(f"{subplot = }")
subplot.plot_matplotlib(ax, layers=layers)
# ax.set_title(f"Subplot ({row}, {col})")
ax.grid()
Expand Down
1 change: 1 addition & 0 deletions src/maxplotlib/subfigure/line_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def add_node(self, x, y, label=None, content="", layer=0, **kwargs):
if layer in self.layers:
self.layers[layer].add(node)
else:
# print(f"{self.layers = } {layer = }")
self.layers[layer] = Tikzlayer(layer)
self.layers[layer].add(node)
self._node_counter += 1
Expand Down
2 changes: 1 addition & 1 deletion src/maxplotlib/subfigure/tikz_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def compile_pdf(self, filename="output.pdf"):
else:
print("PDF compilation failed. Please check the LaTeX log for details.")

def plot_matplotlib(self, ax):
def plot_matplotlib(self, ax, layers=None):
"""
Plot all nodes and paths on the provided axis using Matplotlib.

Expand Down
103 changes: 103 additions & 0 deletions tutorials/tutorial_01.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"\n",
"# Tutorial 1\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"import maxplotlib.canvas.canvas as canvas\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"c = canvas.Canvas(width=\"17cm\", ratio=0.5, fontsize=12)\n",
"sp = c.add_subplot(\n",
" grid=True, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
")\n",
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n",
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n",
"c.plot()\n",
"c.savefig(filename=\"tutorial_01_01.pdf\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"c = canvas.Canvas(width=\"17cm\", ncols=2, nrows=2, ratio=0.5)\n",
"sp = c.add_subplot(grid=True)\n",
"c.add_subplot(row=1)\n",
"sp2 = c.add_subplot(row=1, legend=False)\n",
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n",
"sp2.add_line(\n",
" [0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\"\n",
")\n",
"c.plot(backend=\"matplotlib\")\n",
"c.plot(backend=\"plotly\")\n",
"c.savefig(filename=\"tutorial_01_02.pdf\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"# Test with plotly backend\n",
"c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n",
"sp = c.add_subplot(\n",
" grid=True, xlabel=\"x (mm)\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
")\n",
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\", linestyle=\"-.\")\n",
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n",
"c.plot(backend=\"matplotlib\")\n",
"c.plot(backend=\"plotly\")\n",
"c.savefig(filename=\"tutorial_01_03.pdf\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "env_maxplotlib",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading