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.
Files changed (61) hide show
  1. {mgplot-0.2.30 → mgplot-0.2.31}/CHANGELOG.md +18 -0
  2. {mgplot-0.2.30 → mgplot-0.2.31}/PKG-INFO +1 -1
  3. {mgplot-0.2.30 → mgplot-0.2.31}/pyproject.toml +1 -1
  4. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/finalise_plot.py +45 -13
  5. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_axvline_text.py +30 -1
  6. {mgplot-0.2.30 → mgplot-0.2.31}/uv.lock +7 -7
  7. {mgplot-0.2.30 → mgplot-0.2.31}/.claude/settings.local.json +0 -0
  8. {mgplot-0.2.30 → mgplot-0.2.31}/.gitignore +0 -0
  9. {mgplot-0.2.30 → mgplot-0.2.31}/.pylintrc +0 -0
  10. {mgplot-0.2.30 → mgplot-0.2.31}/.python-version +0 -0
  11. {mgplot-0.2.30 → mgplot-0.2.31}/LICENSE +0 -0
  12. {mgplot-0.2.30 → mgplot-0.2.31}/README.md +0 -0
  13. {mgplot-0.2.30 → mgplot-0.2.31}/build-all.sh +0 -0
  14. {mgplot-0.2.30 → mgplot-0.2.31}/build-docs.sh +0 -0
  15. {mgplot-0.2.30 → mgplot-0.2.31}/docs/index.html +0 -0
  16. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/bar_plot.html +0 -0
  17. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/fill_between_plot.html +0 -0
  18. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/finalise_plot.html +0 -0
  19. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/growth_plot.html +0 -0
  20. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/line_plot.html +0 -0
  21. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/postcovid_plot.html +0 -0
  22. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/revision_plot.html +0 -0
  23. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/run_plot.html +0 -0
  24. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/seastrend_plot.html +0 -0
  25. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot/summary_plot.html +0 -0
  26. {mgplot-0.2.30 → mgplot-0.2.31}/docs/mgplot.html +0 -0
  27. {mgplot-0.2.30 → mgplot-0.2.31}/docs/search.js +0 -0
  28. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/__init__.py +0 -0
  29. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/annotation_utils.py +0 -0
  30. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/axis_utils.py +0 -0
  31. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/bar_plot.py +0 -0
  32. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/colors.py +0 -0
  33. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/fill_between_plot.py +0 -0
  34. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/finalisers.py +0 -0
  35. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/growth_plot.py +0 -0
  36. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/keyword_checking.py +0 -0
  37. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/line_plot.py +0 -0
  38. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/lint-all.sh +0 -0
  39. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/multi_plot.py +0 -0
  40. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/postcovid_plot.py +0 -0
  41. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/py.typed +0 -0
  42. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/revision_plot.py +0 -0
  43. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/run_plot.py +0 -0
  44. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/seastrend_plot.py +0 -0
  45. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/settings.py +0 -0
  46. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/summary_plot.py +0 -0
  47. {mgplot-0.2.30 → mgplot-0.2.31}/src/mgplot/utilities.py +0 -0
  48. {mgplot-0.2.30 → mgplot-0.2.31}/test/test-executed.ipynb +0 -0
  49. {mgplot-0.2.30 → mgplot-0.2.31}/test/test.ipynb +0 -0
  50. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_annotation_collision.py +0 -0
  51. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_bar_horizontal.py +0 -0
  52. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_bar_string_index.py +0 -0
  53. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_chart_subdir.py +0 -0
  54. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_multi_series_ticks.py +0 -0
  55. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_splat_sequences.py +0 -0
  56. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_tick_relabel.py +0 -0
  57. {mgplot-0.2.30 → mgplot-0.2.31}/test/test_zorder.py +0 -0
  58. {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/ocr_rba.csv +0 -0
  59. {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/revisions.csv +0 -0
  60. {mgplot-0.2.30 → mgplot-0.2.31}/test/zz-test-data/summary.csv +0 -0
  61. {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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mgplot
3
- Version: 0.2.30
3
+ Version: 0.2.31
4
4
  Summary: mgplot is a time-series/PeriodIndex frontend for matplotlib
5
5
  Project-URL: Repository, https://github.com/bpalmer4/mgplot
6
6
  Project-URL: Homepage, https://github.com/bpalmer4/mgplot
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mgplot"
3
- version = "0.2.30"
3
+ version = "0.2.31"
4
4
  description = "mgplot is a time-series/PeriodIndex frontend for matplotlib"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -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] = 3.0 # points, to the right of the line
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
- _VLINE_LOCATIONS: Final[tuple[str, ...]] = ("auto", "top", "bottom")
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
- if loc not in _VLINE_LOCATIONS:
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 the right of a vertical line.
394
+ """Place a rotated text label just to one side of a vertical line.
366
395
 
367
- The label is anchored with x in data coordinates and y in axes
368
- coordinates, so it stays pinned to the top/bottom of the plot regardless
369
- of any later change to the y-limits.
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
- if loc == "auto":
374
- loc = _auto_vline_loc(axes, float(x))
375
- y, valign = (1.0 - VLINE_TEXT_PAD, "top") if loc == "top" else (VLINE_TEXT_PAD, "bottom")
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": "left",
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=(VLINE_TEXT_OFFSET, 0),
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.30"
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.10.1"
1294
+ version = "4.11.0"
1295
1295
  source = { registry = "https://pypi.org/simple" }
1296
- sdist = { url = "https://files.pythonhosted.org/packages/52/cd/4f25b2f95b23f5d2c9c1fe43e49841bff5800562149b2666afc09309aa8f/platformdirs-4.10.1.tar.gz", hash = "sha256:ceab4084426fe6319ce18e86deada8ab1b7487c7aee7040c55e277c9ae793695", size = 31678, upload-time = "2026-07-18T03:53:43.808Z" }
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/ec/73/6fd0bb9ce84138c3857f12e9de63bc901852975a092d545f18087a204aa2/platformdirs-4.10.1-py3-none-any.whl", hash = "sha256:0e4eff26be2d75293977f7cddc153fd9b8eaa7fb0c7b64ffe4076cb443117443", size = 22906, upload-time = "2026-07-18T03:53:42.576Z" },
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/80/f1/93422647dd7e461f23d254e6b2bfa687a85b53aeb4903fcdbb74474d4584/soupsieve-2.9.tar.gz", hash = "sha256:acee8417325c5653e1377dc31eccad59eb82cbc65942afe6174c53b3aaad63fc", size = 122122, upload-time = "2026-07-19T01:35:18.425Z" }
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/7b/d6/3185ab5ad1280319b31986898f3206dd7227cd75e293d4dba2a5e6bf27a0/soupsieve-2.9-py3-none-any.whl", hash = "sha256:a2b2c76d67df2382d245409fd71e321a571717e58463efa32ace87dcadac2c12", size = 37387, upload-time = "2026-07-19T01:35:17.106Z" },
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