-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.qmd
More file actions
139 lines (100 loc) · 3.06 KB
/
README.qmd
File metadata and controls
139 lines (100 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
title: Maxlotlib
format: gfm
fig-dpi: 150
---
# Maxplotlib
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
```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()
```
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")
```
### Horizontal Subplots with TikZ Backend
The tikzfigure backend supports creating side-by-side subplots (1×n layouts):
```{python}
#| label: fig-showcase-subplots
#| fig-width: 9
#| fig-height: 6
x = np.linspace(0, 2 * np.pi, 200)
canvas, (ax1, ax2) = Canvas.subplots(ncols=2, width="10cm", ratio=0.3)
ax1.plot(x, np.sin(x), color="royalblue")
ax1.set_title("sin(x)")
ax2.plot(x, np.cos(x), color="tomato")
ax2.set_title("cos(x)")
canvas.suptitle("Trigonometric Functions")
canvas.show(backend="tikzfigure") # Generates LaTeX subfigures
```
**Note:** Only horizontal layouts (1×n) are currently supported with the tikzfigure backend. Vertical/grid layouts will raise `NotImplementedError`. See the tutorials for more examples.
### Terminal Backend with plotext
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")
```
### 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()
```