mgplot 0.2.30__tar.gz → 0.2.31__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mgplot-0.2.30 → mgplot-0.2.31}/CHANGELOG.md +18 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/PKG-INFO +1 -1
- {mgplot-0.2.30 → mgplot-0.2.31}/pyproject.toml +1 -1
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/finalise_plot.py +45 -13
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_axvline_text.py +30 -1
- {mgplot-0.2.30 → mgplot-0.2.31}/uv.lock +7 -7
- {mgplot-0.2.30 → mgplot-0.2.31}/.claude/settings.local.json +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/.gitignore +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/.pylintrc +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/.python-version +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/LICENSE +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/README.md +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/build-all.sh +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/build-docs.sh +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/index.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/bar_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/fill_between_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/finalise_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/growth_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/line_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/postcovid_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/revision_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/run_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/seastrend_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/summary_plot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot.html +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/docs/search.js +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/__init__.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/annotation_utils.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/axis_utils.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/bar_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/colors.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/fill_between_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/finalisers.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/growth_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/keyword_checking.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/line_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/lint-all.sh +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/multi_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/postcovid_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/py.typed +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/revision_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/run_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/seastrend_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/settings.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/summary_plot.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/utilities.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test-executed.ipynb +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test.ipynb +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_annotation_collision.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_bar_horizontal.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_bar_string_index.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_chart_subdir.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_multi_series_ticks.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_splat_sequences.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_tick_relabel.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/test_zorder.py +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/ocr_rba.csv +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/revisions.csv +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/summary.csv +0 -0
- {mgplot-0.2.30 → mgplot-0.2.31}/uv-upgrade.sh +0 -0
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
Version 0.2.31 - released 22-Jul-2026 (Canberra, Australia)
|
|
2
|
+
|
|
3
|
+
* enhancement
|
|
4
|
+
- the loc key on an annotated axvline label now chooses which flank of the
|
|
5
|
+
line the label sits on, as well as which end of the plot. loc is a
|
|
6
|
+
space-separated string mixing a vertical word ("auto", the default, or
|
|
7
|
+
"top"/"bottom") with a side word ("left"/"right"); either may be omitted
|
|
8
|
+
and the order does not matter. The side places the rotated label on the
|
|
9
|
+
left or right of the line, VLINE_TEXT_OFFSET points away. An omitted side
|
|
10
|
+
defaults to "right", so a bare "auto"/"top"/"bottom" - and any code
|
|
11
|
+
written against 0.2.30 - behaves exactly as before. A loc naming two
|
|
12
|
+
vertical words, two side words, or an unrecognised word raises, as each
|
|
13
|
+
is a typo rather than a choice.
|
|
14
|
+
- the default gap between a label and its line (VLINE_TEXT_OFFSET) is now
|
|
15
|
+
2 points rather than 3, pulling the text in a little closer.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
1
19
|
Version 0.2.30 - released 21-Jul-2026 (Canberra, Australia)
|
|
2
20
|
|
|
3
21
|
* enhancement
|
|
@@ -35,7 +35,7 @@ DEFAULT_FILE_TITLE_NAME: Final[str] = "plot"
|
|
|
35
35
|
# --- annotated axvline text
|
|
36
36
|
VLINE_TEXT_FONTSIZE: Final[str] = "xx-small"
|
|
37
37
|
VLINE_TEXT_ROTATION: Final[int] = 90
|
|
38
|
-
VLINE_TEXT_OFFSET: Final[float] =
|
|
38
|
+
VLINE_TEXT_OFFSET: Final[float] = 2.0 # points, to the right of the line
|
|
39
39
|
VLINE_TEXT_PAD: Final[float] = 0.01 # axes fraction, in from the top/bottom
|
|
40
40
|
VLINE_AUTO_BAND: Final[float] = 0.02 # fraction of the x-span sampled either side
|
|
41
41
|
|
|
@@ -284,7 +284,37 @@ def _convert_period_value(axes: Axes, setting: str, value: object) -> object:
|
|
|
284
284
|
# --- annotated vertical lines
|
|
285
285
|
# "text", "loc" and "text_kwargs" in an axvline dict describe its label rather
|
|
286
286
|
# than the line, and are popped before the dict is splatted into ax.axvline().
|
|
287
|
-
|
|
287
|
+
# loc is a space-separated string mixing a vertical word ("auto"/"top"/"bottom")
|
|
288
|
+
# with a side word ("left"/"right"); either may be omitted. The side picks which
|
|
289
|
+
# flank of the line the rotated label sits on, VLINE_TEXT_OFFSET points away.
|
|
290
|
+
_VLINE_EDGES: Final[tuple[str, ...]] = ("top", "bottom")
|
|
291
|
+
_VLINE_SIDES: Final[tuple[str, ...]] = ("left", "right")
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _parse_vline_loc(loc: object) -> tuple[str, str]:
|
|
295
|
+
"""Split a loc string into (edge, side), order-free and each optional.
|
|
296
|
+
|
|
297
|
+
edge is "auto", "top" or "bottom"; side is "left" or "right". An omitted
|
|
298
|
+
edge falls back to "auto" (choose by the data) and an omitted side to
|
|
299
|
+
"right" (today's placement). Raises on an unrecognised or doubled word --
|
|
300
|
+
each is a typo, not a choice.
|
|
301
|
+
"""
|
|
302
|
+
if not isinstance(loc, str):
|
|
303
|
+
raise TypeError(f"axvline 'loc' must be a string, got {type(loc)}")
|
|
304
|
+
edge: str | None = None
|
|
305
|
+
side: str | None = None
|
|
306
|
+
for tok in loc.split():
|
|
307
|
+
if tok == "auto" or tok in _VLINE_EDGES:
|
|
308
|
+
if edge is not None:
|
|
309
|
+
raise ValueError(f"axvline 'loc' names two vertical positions, got {loc!r}")
|
|
310
|
+
edge = tok
|
|
311
|
+
elif tok in _VLINE_SIDES:
|
|
312
|
+
if side is not None:
|
|
313
|
+
raise ValueError(f"axvline 'loc' names two sides, got {loc!r}")
|
|
314
|
+
side = tok
|
|
315
|
+
else:
|
|
316
|
+
raise ValueError(f"axvline 'loc' word {tok!r} not recognised in {loc!r}")
|
|
317
|
+
return edge or "auto", side or "right"
|
|
288
318
|
|
|
289
319
|
|
|
290
320
|
def _pop_vline_text(item: dict[str, Any]) -> tuple[str, str, dict[str, Any]] | None:
|
|
@@ -301,8 +331,7 @@ def _pop_vline_text(item: dict[str, Any]) -> tuple[str, str, dict[str, Any]] | N
|
|
|
301
331
|
if loc != "auto" or text_kwargs:
|
|
302
332
|
raise ValueError("axvline 'loc'/'text_kwargs' given without any 'text' to place")
|
|
303
333
|
return None
|
|
304
|
-
|
|
305
|
-
raise ValueError(f"axvline 'loc' must be one of {_VLINE_LOCATIONS}, got {loc!r}")
|
|
334
|
+
_parse_vline_loc(loc) # validate now; raises on a bad loc string
|
|
306
335
|
if not isinstance(text_kwargs, dict):
|
|
307
336
|
raise TypeError(f"axvline 'text_kwargs' must be a dict, got {type(text_kwargs)}")
|
|
308
337
|
return str(text), loc, text_kwargs
|
|
@@ -362,23 +391,26 @@ def _auto_vline_loc(axes: Axes, x: float) -> str:
|
|
|
362
391
|
|
|
363
392
|
|
|
364
393
|
def _annotate_vline(axes: Axes, item: dict[str, Any], line: Line2D, spec: tuple[str, str, dict]) -> None:
|
|
365
|
-
"""Place a rotated text label just to
|
|
394
|
+
"""Place a rotated text label just to one side of a vertical line.
|
|
366
395
|
|
|
367
|
-
The
|
|
368
|
-
|
|
369
|
-
of any later change to the
|
|
396
|
+
The side (left/right of the line) comes from loc; the label is anchored
|
|
397
|
+
with x in data coordinates and y in axes coordinates, so it stays pinned
|
|
398
|
+
to the top/bottom of the plot regardless of any later change to the
|
|
399
|
+
y-limits.
|
|
370
400
|
"""
|
|
371
401
|
text, loc, text_kwargs = spec
|
|
372
402
|
x = item.get("x", 0) # matches the matplotlib default for axvline
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
403
|
+
edge, side = _parse_vline_loc(loc)
|
|
404
|
+
if edge == "auto":
|
|
405
|
+
edge = _auto_vline_loc(axes, float(x))
|
|
406
|
+
y, valign = (1.0 - VLINE_TEXT_PAD, "top") if edge == "top" else (VLINE_TEXT_PAD, "bottom")
|
|
407
|
+
x_off, halign = (VLINE_TEXT_OFFSET, "left") if side == "right" else (-VLINE_TEXT_OFFSET, "right")
|
|
376
408
|
|
|
377
409
|
options: dict[str, Any] = {
|
|
378
410
|
"rotation": VLINE_TEXT_ROTATION,
|
|
379
411
|
"fontsize": VLINE_TEXT_FONTSIZE,
|
|
380
412
|
"color": line.get_color(),
|
|
381
|
-
"ha":
|
|
413
|
+
"ha": halign,
|
|
382
414
|
"va": valign,
|
|
383
415
|
}
|
|
384
416
|
options.update(text_kwargs)
|
|
@@ -386,7 +418,7 @@ def _annotate_vline(axes: Axes, item: dict[str, Any], line: Line2D, spec: tuple[
|
|
|
386
418
|
text,
|
|
387
419
|
xy=(x, y),
|
|
388
420
|
xycoords=blended_transform_factory(axes.transData, axes.transAxes),
|
|
389
|
-
xytext=(
|
|
421
|
+
xytext=(x_off, 0),
|
|
390
422
|
textcoords="offset points",
|
|
391
423
|
**options,
|
|
392
424
|
)
|
|
@@ -15,7 +15,7 @@ from matplotlib.font_manager import FontProperties
|
|
|
15
15
|
from matplotlib.text import Annotation
|
|
16
16
|
|
|
17
17
|
from mgplot import bar_plot, line_plot
|
|
18
|
-
from mgplot.finalise_plot import VLINE_TEXT_FONTSIZE, finalise_plot
|
|
18
|
+
from mgplot.finalise_plot import VLINE_TEXT_FONTSIZE, VLINE_TEXT_OFFSET, finalise_plot
|
|
19
19
|
|
|
20
20
|
IDX = pd.period_range("2020-01", periods=24, freq="M")
|
|
21
21
|
|
|
@@ -158,6 +158,34 @@ def test_explicit_loc_overrides_auto() -> None:
|
|
|
158
158
|
print("PASS: explicit loc overrides auto")
|
|
159
159
|
|
|
160
160
|
|
|
161
|
+
def test_side_word_flips_label_to_the_left() -> None:
|
|
162
|
+
"""A 'left' side word should flip the label to the left flank of the line.
|
|
163
|
+
|
|
164
|
+
Uses 'top left' so both knobs are exercised at once: 'top' must still set
|
|
165
|
+
va='top', while 'left' must set ha='right' and a negative x-offset. The
|
|
166
|
+
default (right) placement would give ha='left' and a positive offset, so
|
|
167
|
+
this cannot pass down the unchanged path.
|
|
168
|
+
"""
|
|
169
|
+
series = pd.Series(np.linspace(0.0, 10.0, 24), index=IDX)
|
|
170
|
+
axes = line_plot(series)
|
|
171
|
+
finalise_plot(
|
|
172
|
+
axes,
|
|
173
|
+
axvline={"x": IDX[12], "text": "flip", "loc": "top left"},
|
|
174
|
+
dont_save=True,
|
|
175
|
+
dont_close=True,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
label = _label(axes, "flip")
|
|
179
|
+
valign, halign = label.get_verticalalignment(), label.get_horizontalalignment()
|
|
180
|
+
assert valign == "top", f"Expected va='top' from 'top', got {valign}"
|
|
181
|
+
assert halign == "right", f"Expected ha='right' from 'left', got {halign}"
|
|
182
|
+
x_off, _ = label.get_position() # get_position() is the offset, not the anchor
|
|
183
|
+
assert x_off == -VLINE_TEXT_OFFSET, f"Expected x-offset {-VLINE_TEXT_OFFSET} to the left, got {x_off}"
|
|
184
|
+
|
|
185
|
+
plt.close()
|
|
186
|
+
print("PASS: 'left' side word flips the label to the left flank")
|
|
187
|
+
|
|
188
|
+
|
|
161
189
|
def test_several_labelled_lines() -> None:
|
|
162
190
|
"""A sequence of labelled lines should produce a label per line."""
|
|
163
191
|
series = pd.Series(np.linspace(0.0, 10.0, 24), index=IDX)
|
|
@@ -265,6 +293,7 @@ if __name__ == "__main__":
|
|
|
265
293
|
test_auto_picks_bottom_when_data_is_high()
|
|
266
294
|
test_auto_is_local_not_whole_chart()
|
|
267
295
|
test_explicit_loc_overrides_auto()
|
|
296
|
+
test_side_word_flips_label_to_the_left()
|
|
268
297
|
test_several_labelled_lines()
|
|
269
298
|
test_period_x_with_text()
|
|
270
299
|
test_unlabelled_vline_unchanged()
|
|
@@ -835,7 +835,7 @@ wheels = [
|
|
|
835
835
|
|
|
836
836
|
[[package]]
|
|
837
837
|
name = "mgplot"
|
|
838
|
-
version = "0.2.
|
|
838
|
+
version = "0.2.31"
|
|
839
839
|
source = { editable = "." }
|
|
840
840
|
dependencies = [
|
|
841
841
|
{ name = "matplotlib" },
|
|
@@ -1291,11 +1291,11 @@ wheels = [
|
|
|
1291
1291
|
|
|
1292
1292
|
[[package]]
|
|
1293
1293
|
name = "platformdirs"
|
|
1294
|
-
version = "4.
|
|
1294
|
+
version = "4.11.0"
|
|
1295
1295
|
source = { registry = "https://pypi.org/simple" }
|
|
1296
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
1296
|
+
sdist = { url = "https://files.pythonhosted.org/packages/78/9b/560e4be8e26f6fd133a03630a8df0c663b9e8d61b4ade152b72005aec83b/platformdirs-4.11.0.tar.gz", hash = "sha256:0555d18370482847566ffabcaa53ad7c6c1c29f195989ae1ed634a05f76ea1e0", size = 31953, upload-time = "2026-07-21T13:09:36.565Z" }
|
|
1297
1297
|
wheels = [
|
|
1298
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
1298
|
+
{ url = "https://files.pythonhosted.org/packages/7d/68/d8d58938dfb1370b266a1a729e6d77a985be23689a0496498ee17b2cbf90/platformdirs-4.11.0-py3-none-any.whl", hash = "sha256:360ccded2b7fce0af0ff80cc8f5942a1c5d99b0e856033acb030bfc634709e74", size = 23247, upload-time = "2026-07-21T13:09:35.422Z" },
|
|
1299
1299
|
]
|
|
1300
1300
|
|
|
1301
1301
|
[[package]]
|
|
@@ -1606,11 +1606,11 @@ wheels = [
|
|
|
1606
1606
|
|
|
1607
1607
|
[[package]]
|
|
1608
1608
|
name = "soupsieve"
|
|
1609
|
-
version = "2.9"
|
|
1609
|
+
version = "2.9.1"
|
|
1610
1610
|
source = { registry = "https://pypi.org/simple" }
|
|
1611
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
1611
|
+
sdist = { url = "https://files.pythonhosted.org/packages/d9/38/e12680bbe6b4f8f3d17adcaf38d26850aa756c85cf4a80e79fc12a018fe8/soupsieve-2.9.1.tar.gz", hash = "sha256:c33e6605bbc71dd628b00c632d58ae607c22bade247e52553928f83bbb75b4ba", size = 122261, upload-time = "2026-07-21T16:57:17.452Z" }
|
|
1612
1612
|
wheels = [
|
|
1613
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
1613
|
+
{ url = "https://files.pythonhosted.org/packages/0f/2c/437fe806897c2d6cfdc3ee43a18da8bf8e568530a4ae9bac781541ca9896/soupsieve-2.9.1-py3-none-any.whl", hash = "sha256:4f4477399246b7a0c720a88ca2454b11cd6bb9ae4c9d170140786e916776c14c", size = 37404, upload-time = "2026-07-21T16:57:16.421Z" },
|
|
1614
1614
|
]
|
|
1615
1615
|
|
|
1616
1616
|
[[package]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|