Skip to content
Closed
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
5 changes: 4 additions & 1 deletion .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ jobs:

- name: Test tutorials
run: |
jupyter nbconvert --to notebook --execute tutorials/*.ipynb --output-dir=/tmp --ExecutePreprocessor.timeout=300
# tutorial_07_tikz.ipynb requires pdflatex — skip it in CI
jupyter nbconvert --to notebook --execute \
$(ls tutorials/*.ipynb | grep -v tutorial_07_tikz) \
--output-dir=/tmp --ExecutePreprocessor.timeout=300
79 changes: 72 additions & 7 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- devel

jobs:
static-analysis:
cloc:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
Expand All @@ -24,38 +24,103 @@ jobs:
./cloc --version
./cloc $(git ls-files)

black:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Code formatting with black
run: |
pip install black
pip install "black[jupyter]"
black --check src/
black --check tutorials/

isort:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Code formatting with isort
run: |
pip install isort
isort --check src/
isort --check tutorials/

- name: Code formatting with prospector
mypy:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Type check with mypy
continue-on-error: true
run: |
pip install mypy
mypy src/

- name: Code formatting with prospector
prospector:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Static analysis with prospector
continue-on-error: true
run: |
pip install prospector
prospector src/

- name: Code formatting with ruff

ruff:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Lint with ruff
continue-on-error: true
run: |
pip install ruff
ruff check src/

- name: Code formatting with pylint
pylint:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Lint with pylint
continue-on-error: true
run: |
pip install pylint
Expand Down
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ cython_debug/

# Figures and videos
figures/
*.png
#*.png
*.pdf
*.jpg
*.jpeg
Expand All @@ -188,4 +188,12 @@ figures/
env*

# VS code
.vscode/*
.vscode/*

# Outputs
docs/.astro/
docs/node_modules/
docs/superpowers/
docs/tutorials/
tutorials/*.txt
tutorials/*.png
118 changes: 107 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,123 @@
# maxplotlib
# Maxplotlib

This is a wrapper for matplotlib so I can produce figures with consistent formatting. It also has some pretty nice additions such as using layers and exporting to tikz.
A clean, expressive wrapper around **Matplotlib**, **Plotly**,
**plotext**, and **tikzfigure** for producing publication-quality
figures with minimal boilerplate. Swap backends without rewriting your
data — render the same canvas as a crisp PNG, an interactive Plotly
chart, a terminal-native plotext figure, or camera-ready **TikZ** code
for LaTeX.

## Install

Create and activate python environment
``` bash
pip install maxplotlibx
```

## Showcase

### Quickstart

``` python
import numpy as np
from maxplotlib import Canvas

x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)

canvas, ax = Canvas.subplots()
ax.plot(x, y)
```

Plot the figure with the default (matplotlib) backend:

``` python
canvas.show()
```

![](README_files/figure-markdown_strict/cell-3-output-1.png)

Render the same line graph directly in the terminal with the `plotext`
backend:

``` python
terminal_fig = canvas.plot(backend="plotext")
print(terminal_fig.build(keep_colors=False))
```

Or plot with the TikZ backend:

``` python
canvas.show(backend="tikzfigure")
```
python -m venv env
source env/bin/activate
pip install --upgrade pip

![](README_files/figure-markdown_strict/cell-4-output-1.png)

### Terminal backend

The `plotext` backend is designed for terminal-first workflows. It
currently supports line plots, scatter plots, bars, filled regions,
error bars, reference lines, text/annotations, labels/titles, log
axes, layers, matrix-style `imshow()` rendering, common patches, and
multi-subplot canvases.

``` python
x = np.linspace(1, 10, 40)

canvas, ax = Canvas.subplots()
ax.plot(x, np.sqrt(x), color="cyan", label="sqrt(x)")
ax.errorbar(x[::8], np.sqrt(x[::8]), yerr=0.15, color="yellow", label="samples")
ax.set_title("Terminal plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_xscale("log")
ax.set_legend(True)

canvas.show(backend="plotext")
```

Install the code and requirements with pip
## Examples

Runnable example scripts live in `examples/`:

``` bash
python examples/plotly_backend_basic.py
python examples/plotly_backend_parity.py
```
pip install -e .

### Layers

``` python
x = np.linspace(0, 2 * np.pi, 200)

canvas, ax = Canvas.subplots(width="10cm", ratio=0.55)

ax.plot(x, np.sin(x), color="steelblue", label=r"$\sin(x)$", layer=0)
ax.plot(x, np.cos(x), color="tomato", label=r"$\cos(x)$", layer=1)
ax.plot(
x,
np.sin(x) * np.cos(x),
color="seagreen",
label=r"$\sin(x)\cos(x)$",
linestyle="dashed",
layer=2,
)

ax.set_xlabel("x")
ax.set_legend(True)
```

Additional dependencies for developers can be installed with
Show layer 0 only, then layers 0 and 1, then everything:

``` python
canvas.show(layers=[0])
```
pip install -e ".[dev]"

![](README_files/figure-markdown_strict/cell-6-output-1.png)

Show all layers:

``` python
canvas.show()
```

Some examples can be found in `tutorials/`
![](README_files/figure-markdown_strict/cell-7-output-1.png)
Loading
Loading