|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
1 | 5 | import warnings
|
2 |
| -from typing import Optional, Union |
3 | 6 | from datetime import timedelta
|
4 | 7 | import matplotlib.pyplot as plt
|
5 | 8 | import numpy as np
|
|
17 | 20 | from .line_label import LineLabel
|
18 | 21 | from .utils import maximum_bipartite_matching, normalize_xydata
|
19 | 22 |
|
| 23 | +if TYPE_CHECKING: |
| 24 | + from line_label import Position |
| 25 | + |
20 | 26 |
|
21 | 27 | # Label line with line2D label data
|
22 | 28 | def labelLine(
|
23 | 29 | line: Line2D,
|
24 |
| - x, |
25 |
| - label: Optional[str] = None, |
26 |
| - align: Optional[bool] = None, |
| 30 | + x: Position, |
| 31 | + label: str | None = None, |
| 32 | + align: bool | None = None, |
27 | 33 | drop_label: bool = False,
|
28 | 34 | xoffset: float = 0,
|
29 | 35 | xoffset_logspace: bool = False,
|
30 | 36 | yoffset: float = 0,
|
31 | 37 | yoffset_logspace: bool = False,
|
32 | 38 | outline_color: str = "auto",
|
33 | 39 | outline_width: float = 8,
|
34 |
| - rotation: Optional[float] = None, |
| 40 | + rotation: float | None = None, |
35 | 41 | **kwargs,
|
36 | 42 | ):
|
37 | 43 | """
|
@@ -107,16 +113,16 @@ def labelLine(
|
107 | 113 |
|
108 | 114 |
|
109 | 115 | def labelLines(
|
110 |
| - lines: Optional[list[Line2D]] = None, |
111 |
| - align: Optional[bool] = None, |
112 |
| - xvals: Optional[Union[tuple[float, float], list[float]]] = None, |
| 116 | + lines: list[Line2D] | None = None, |
| 117 | + align: bool | None = None, |
| 118 | + xvals: tuple[Position, Position] | list[Position] | None = None, |
113 | 119 | drop_label: bool = False,
|
114 | 120 | shrink_factor: float = 0.05,
|
115 |
| - xoffsets: Union[float, list[float]] = 0, |
116 |
| - yoffsets: Union[float, list[float]] = 0, |
| 121 | + xoffsets: float | list[float] = 0, |
| 122 | + yoffsets: float | list[float] = 0, |
117 | 123 | outline_color: str = "auto",
|
118 | 124 | outline_width: float = 5,
|
119 |
| - rotation: Optional[bool] = None, |
| 125 | + rotation: bool | None = None, |
120 | 126 | **kwargs,
|
121 | 127 | ):
|
122 | 128 | """Label all lines with their respective legends.
|
@@ -266,8 +272,9 @@ def labelLines(
|
266 | 272 | if not (xmin <= xv <= xmax):
|
267 | 273 | warnings.warn(
|
268 | 274 | (
|
269 |
| - f"The value at position {i} in `xvals` is outside the range of its " |
270 |
| - f"associated line ({xmin=}, {xmax=}, xval={xv}). " |
| 275 | + f"The value at position {i} in `xvals` is outside the " |
| 276 | + "range of its associated line " |
| 277 | + f"({xmin=}, {xmax=}, xval={xv}). " |
271 | 278 | "Clipping it into the allowed range."
|
272 | 279 | ),
|
273 | 280 | UserWarning,
|
|
0 commit comments