Skip to content

Commit 7f9da67

Browse files
committed
version 0.3.2: new transpose argument for wrap
1 parent 9fa115a commit 7f9da67

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ Fix:
2424

2525
* Missing title parameter from border.
2626

27+
Version 0.3.2
28+
-------------
29+
30+
New:
31+
32+
* Transpose parameter for wrap.
33+
2734
Version 0.3.1
2835
-------------
2936

DOCS.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ import numpy as np
6565

6666
xs = np.linspace(-2*np.pi, +2*np.pi, 156)
6767

68-
plot = mp.border(
68+
plot = mp.axes(
6969
mp.scatter(
7070
(xs, 1.0 * np.cos(xs), "red"),
7171
(xs, 0.9 * np.cos(xs - 0.33 * np.pi), "magenta"),
7272
(xs, 0.8 * np.cos(xs - 0.66 * np.pi), "blue"),
7373
(xs, 0.7 * np.cos(xs - 1.00 * np.pi), "cyan"),
7474
(xs, 0.8 * np.cos(xs - 1.33 * np.pi), "green"),
7575
(xs, 0.9 * np.cos(xs - 1.66 * np.pi), "yellow"),
76-
mp.xaxis(-2*np.pi, +2*np.pi, 156),
77-
mp.yaxis(-1, 1, 40),
78-
width=78,
76+
width=75,
7977
height=10,
8078
yrange=(-1,1),
81-
)
82-
/ mp.center(mp.text(f"cos(x + 2 pi k / 6)"), width=78)
79+
),
80+
title=" y = cos(x + 2πk/6) ",
81+
xlabel="x",
82+
ylabel="y",
8383
)
8484
```
8585

@@ -1184,16 +1184,20 @@ Inputs:
11841184
The number of columns in the grid. If not provided, it is automatically
11851185
determined based on the terminal width and the width of the largest
11861186
plot.
1187+
* transpose: optional bool (default False).
1188+
If False (default), the plots are arranged in reading order, from left
1189+
to right and then from top to bottom. If True, the plots are arranged
1190+
in column order, from top to bottom and then from left to right.
11871191

11881192
### method wrap.\_\_repr\_\_
11891193

1190-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1552))
1194+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1563))
11911195

11921196
---
11931197

11941198
### class center
11951199

1196-
**center(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1559))
1200+
**center(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1570))
11971201

11981202
Pad a plot with blank space to center it within a larger area.
11991203

@@ -1214,13 +1218,13 @@ Inputs:
12141218

12151219
### method center.\_\_repr\_\_
12161220

1217-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1611))
1221+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1622))
12181222

12191223
---
12201224

12211225
### function save\_animation
12221226

1223-
**save\_animation(plots: Sequence[plot], filename: str, upscale: int, downscale: int, bgcolor: ColorLike | None, fps: int, repeat: bool):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1622))
1227+
**save\_animation(plots: Sequence[plot], filename: str, upscale: int, downscale: int, bgcolor: ColorLike | None, fps: int, repeat: bool):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1633))
12241228

12251229
Supply a list of plots and a filename and this method will create an
12261230
animated gif.

matthewplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66

7-
__version__ = "0.3.1"
7+
__version__ = "0.3.2"
88

99

1010
from matthewplotlib.plots import (

matthewplotlib/plots.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,13 +1508,18 @@ class wrap(plot):
15081508
The number of columns in the grid. If not provided, it is automatically
15091509
determined based on the terminal width and the width of the largest
15101510
plot.
1511+
* transpose: optional bool (default False).
1512+
If False (default), the plots are arranged in reading order, from left
1513+
to right and then from top to bottom. If True, the plots are arranged
1514+
in column order, from top to bottom and then from left to right.
15111515
"""
15121516
def __init__(
15131517
self,
15141518
*plots: plot,
15151519
cols: int | None = None,
1520+
transpose: bool = False,
15161521
):
1517-
# match size
1522+
# determine and standardise cell size
15181523
cell_height = max(p.height for p in plots)
15191524
cell_width = max(p.width for p in plots)
15201525
padded_chars = [
@@ -1523,28 +1528,34 @@ def __init__(
15231528
right=cell_width - p.width,
15241529
) for p in plots
15251530
]
1531+
blank_cell = CharArray.from_size(
1532+
height=cell_height,
1533+
width=cell_width,
1534+
)
15261535

1527-
# wrap list
1536+
# determine grid size and initialise grid
15281537
if cols is None:
15291538
cols = max(1, os.get_terminal_size()[0] // cell_width)
15301539
n = len(padded_chars)
1531-
wrapped_chars = [padded_chars[i:i+cols] for i in range(0, n, cols)]
1532-
1533-
# correct final row
1534-
if len(wrapped_chars) > 1 and len(wrapped_chars[-1]) < cols:
1535-
buffer = CharArray.from_size(
1536-
height=cell_height,
1537-
width=cell_width * (cols - len(wrapped_chars[-1])),
1538-
)
1539-
wrapped_chars[-1].append(buffer)
1540+
full_rows, spare = divmod(n, cols)
1541+
rows = full_rows + bool(spare)
1542+
grid = [[blank_cell for _ in range(cols)] for _ in range(rows)]
1543+
1544+
# populate grid
1545+
for i, p in enumerate(padded_chars):
1546+
if transpose:
1547+
c, r = divmod(i, rows)
1548+
else:
1549+
r, c = divmod(i, cols)
1550+
grid[r][c] = p
15401551

15411552
# combine into new char array
15421553
blocked_chars = CharArray(
1543-
codes=np.block([[c.codes for c in row] for row in wrapped_chars]),
1544-
fg=np.block([[c.fg for c in row] for row in wrapped_chars]),
1545-
fg_rgb=np.block([[[c.fg_rgb] for c in row] for row in wrapped_chars]),
1546-
bg=np.block([[c.bg for c in row] for row in wrapped_chars]),
1547-
bg_rgb=np.block([[[c.bg_rgb] for c in row] for row in wrapped_chars]),
1554+
codes=np.block([[c.codes for c in row] for row in grid]),
1555+
fg=np.block([[c.fg for c in row] for row in grid]),
1556+
fg_rgb=np.block([[[c.fg_rgb] for c in row] for row in grid]),
1557+
bg=np.block([[c.bg for c in row] for row in grid]),
1558+
bg_rgb=np.block([[[c.bg_rgb] for c in row] for row in grid]),
15481559
)
15491560
super().__init__(blocked_chars)
15501561
self.plots = plots

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "matthewplotlib"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
authors = [
55
{ name="Matthew Farrugia-Roberts", email="[email protected]" },
66
]

0 commit comments

Comments
 (0)