diff --git a/.gitignore b/.gitignore index 4f40a94..b5b8334 100644 --- a/.gitignore +++ b/.gitignore @@ -164,7 +164,7 @@ cython_debug/ # Figures and videos figures/ -*.png +#*.png *.pdf *.jpg *.jpeg @@ -188,4 +188,4 @@ figures/ env* # VS code -.vscode/* \ No newline at end of file +.vscode/* diff --git a/README.md b/README.md index 1b21732..95baae7 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,85 @@ -# maxplotlib +# Maxlotlib -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. + +# Maxplotlib + +A clean, expressive wrapper around **Matplotlib** **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, 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) ``` -python -m venv env -source env/bin/activate -pip install --upgrade pip + +Plot the figure with the default (matplotlib) backend: + +``` python +canvas.show() ``` -Install the code and requirements with pip +![](README_files/figure-markdown_strict/cell-3-output-1.png) + +Alternatively, plot with the TikZ backend (not done yet): +``` python +canvas.show(backend="tikzfigure") ``` -pip install -e . + +![](README_files/figure-markdown_strict/cell-4-output-1.png) + +### 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/` \ No newline at end of file +![](README_files/figure-markdown_strict/cell-7-output-1.png) diff --git a/README.qmd b/README.qmd new file mode 100644 index 0000000..980b775 --- /dev/null +++ b/README.qmd @@ -0,0 +1,86 @@ +--- +title: Maxlotlib +format: gfm +fig-dpi: 150 +--- + +# Maxplotlib + +A clean, expressive wrapper around **Matplotlib** **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, or camera-ready **TikZ** code for LaTeX. + +## Install + +```bash +pip install maxplotlibx +``` + +## Showcase + +### Quickstart + +```{python} +#| label: fig-showcase-1 +#| fig-width: 9 +#| fig-height: 6 + +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() +``` + +Alternatively, plot with the TikZ backend (not done yet): + +```{python} +canvas.show(backend="tikzfigure") +``` + +### Layers + +```{python} +#| label: fig-showcase-2 +#| fig-width: 9 +#| fig-height: 6 + +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) +``` + +Show layer 0 only, then layers 0 and 1, then everything: + +```{python} +canvas.show(layers=[0]) +``` + +Show all layers: + +```{python} +canvas.show() +``` diff --git a/README_files/figure-markdown_strict/cell-3-output-1.png b/README_files/figure-markdown_strict/cell-3-output-1.png new file mode 100644 index 0000000..47c9972 Binary files /dev/null and b/README_files/figure-markdown_strict/cell-3-output-1.png differ diff --git a/README_files/figure-markdown_strict/cell-4-output-1.png b/README_files/figure-markdown_strict/cell-4-output-1.png new file mode 100644 index 0000000..34530c5 Binary files /dev/null and b/README_files/figure-markdown_strict/cell-4-output-1.png differ diff --git a/README_files/figure-markdown_strict/cell-6-output-1.png b/README_files/figure-markdown_strict/cell-6-output-1.png new file mode 100644 index 0000000..56f10fb Binary files /dev/null and b/README_files/figure-markdown_strict/cell-6-output-1.png differ diff --git a/README_files/figure-markdown_strict/cell-7-output-1.png b/README_files/figure-markdown_strict/cell-7-output-1.png new file mode 100644 index 0000000..95dde0b Binary files /dev/null and b/README_files/figure-markdown_strict/cell-7-output-1.png differ