Helper function to replace the values of x and/or y coordinate arrays containing pd.Interval with their mid-points or - for step plots - double points which double the length.
(
xval: np.ndarray, yval: np.ndarray, kwargs: dict
)
| 601 | |
| 602 | |
| 603 | def _resolve_intervals_1dplot( |
| 604 | xval: np.ndarray, yval: np.ndarray, kwargs: dict |
| 605 | ) -> tuple[np.ndarray, np.ndarray, str, str, dict]: |
| 606 | """ |
| 607 | Helper function to replace the values of x and/or y coordinate arrays |
| 608 | containing pd.Interval with their mid-points or - for step plots - double |
| 609 | points which double the length. |
| 610 | """ |
| 611 | x_suffix = "" |
| 612 | y_suffix = "" |
| 613 | |
| 614 | # Is it a step plot? (see matplotlib.Axes.step) |
| 615 | if kwargs.get("drawstyle", "").startswith("steps-"): |
| 616 | remove_drawstyle = False |
| 617 | |
| 618 | # Convert intervals to double points |
| 619 | x_is_interval = _valid_other_type(xval, pd.Interval) |
| 620 | y_is_interval = _valid_other_type(yval, pd.Interval) |
| 621 | if x_is_interval and y_is_interval: |
| 622 | raise TypeError("Can't step plot intervals against intervals.") |
| 623 | elif x_is_interval: |
| 624 | xval, yval = _interval_to_double_bound_points(xval, yval) |
| 625 | remove_drawstyle = True |
| 626 | elif y_is_interval: |
| 627 | yval, xval = _interval_to_double_bound_points(yval, xval) |
| 628 | remove_drawstyle = True |
| 629 | |
| 630 | # Remove steps-* to be sure that matplotlib is not confused |
| 631 | if remove_drawstyle: |
| 632 | del kwargs["drawstyle"] |
| 633 | |
| 634 | # Is it another kind of plot? |
| 635 | else: |
| 636 | # Convert intervals to mid points and adjust labels |
| 637 | if _valid_other_type(xval, pd.Interval): |
| 638 | xval = _interval_to_mid_points(xval) |
| 639 | x_suffix = "_center" |
| 640 | if _valid_other_type(yval, pd.Interval): |
| 641 | yval = _interval_to_mid_points(yval) |
| 642 | y_suffix = "_center" |
| 643 | |
| 644 | # return converted arguments |
| 645 | return xval, yval, x_suffix, y_suffix, kwargs |
| 646 | |
| 647 | |
| 648 | def _resolve_intervals_2dplot(val, func_name): |
no test coverage detected
searching dependent graphs…