mgplot 0.2.30__py3-none-any.whl → 0.2.31__py3-none-any.whl
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/finalise_plot.py +45 -13
- {mgplot-0.2.30.dist-info → mgplot-0.2.31.dist-info}/METADATA +1 -1
- {mgplot-0.2.30.dist-info → mgplot-0.2.31.dist-info}/RECORD +5 -5
- {mgplot-0.2.30.dist-info → mgplot-0.2.31.dist-info}/WHEEL +0 -0
- {mgplot-0.2.30.dist-info → mgplot-0.2.31.dist-info}/licenses/LICENSE +0 -0
mgplot/finalise_plot.py
CHANGED
|
@@ -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
|
)
|
|
@@ -4,7 +4,7 @@ mgplot/axis_utils.py,sha256=-wnjUTL2MdwEntLEVihDABOxLSbux0aSyATCnIsVumg,16041
|
|
|
4
4
|
mgplot/bar_plot.py,sha256=FobAsadYSEf-U0RZFgZutTzse4Rgr0TDFyWUMM68JVs,12513
|
|
5
5
|
mgplot/colors.py,sha256=f5q4z7kORUu66uAxNeK9KAZ64gv_7h_x2qH53BvzwPw,4848
|
|
6
6
|
mgplot/fill_between_plot.py,sha256=XJvtkBeOkohHyayQnu84jURapB5RsMAR-3SaskHkHfM,3361
|
|
7
|
-
mgplot/finalise_plot.py,sha256=
|
|
7
|
+
mgplot/finalise_plot.py,sha256=ttrSy2noxF4EyFlYZJUjy1LICFFE0IuF_26HreeMD1k,24456
|
|
8
8
|
mgplot/finalisers.py,sha256=Wozq4XOmnMdhEB9LJqHao9TrleOfhNV54kRa_bgN-e8,10547
|
|
9
9
|
mgplot/growth_plot.py,sha256=QALNYyINd_u7BL3q-My16eRuhq0LzGfawu-_MsVOXl0,8708
|
|
10
10
|
mgplot/keyword_checking.py,sha256=8CFexwEK_Uyv3_8hAnJ2ewk0tEjNjkwzKfX2uFw2UpM,11446
|
|
@@ -19,7 +19,7 @@ mgplot/seastrend_plot.py,sha256=hi9t0cY0bHdIOU5abLMX7qvAp_hlVLlJFyEKNBzg6Ts,2000
|
|
|
19
19
|
mgplot/settings.py,sha256=RhxgX4d-CgRpvs-ALG_j8tg3wwHSyfvFNdL0aMjofA0,5584
|
|
20
20
|
mgplot/summary_plot.py,sha256=Kg7VD8KFIls4KlD4jeaaXnDw51BZ3p_wMAUpjG49zGQ,11102
|
|
21
21
|
mgplot/utilities.py,sha256=PfzThb_nXYIMhnprQzNcaBqUZV8ysHJte0TU7TIis00,8450
|
|
22
|
-
mgplot-0.2.
|
|
23
|
-
mgplot-0.2.
|
|
24
|
-
mgplot-0.2.
|
|
25
|
-
mgplot-0.2.
|
|
22
|
+
mgplot-0.2.31.dist-info/METADATA,sha256=0qixuMk12Pid95bVjM0aIbo5JqE15yyHLh1JIzyjIeo,7923
|
|
23
|
+
mgplot-0.2.31.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
24
|
+
mgplot-0.2.31.dist-info/licenses/LICENSE,sha256=6ZyruOwF8J7mY25-vZHdOibtY8cSNLz0vWeH59TLhtw,1082
|
|
25
|
+
mgplot-0.2.31.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|