File size: 2,473 Bytes
3e96755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any

import numpy as np

if TYPE_CHECKING:
    import io

    from numpy.typing import ArrayLike

    from contourpy._contourpy import CoordinateArray, FillReturn, FillType, LineReturn, LineType


class Renderer(ABC):
    """Abstract base class for renderers, defining the interface that they must implement."""

    def _grid_as_2d(self, x: ArrayLike, y: ArrayLike) -> tuple[CoordinateArray, CoordinateArray]:
        x = np.asarray(x)
        y = np.asarray(y)
        if x.ndim == 1:
            x, y = np.meshgrid(x, y)
        return x, y

        x = np.asarray(x)
        y = np.asarray(y)
        if x.ndim == 1:
            x, y = np.meshgrid(x, y)
        return x, y

    @abstractmethod
    def filled(

        self,

        filled: FillReturn,

        fill_type: FillType | str,

        ax: Any = 0,

        color: str = "C0",

        alpha: float = 0.7,

    ) -> None:
        pass

    @abstractmethod
    def grid(

        self,

        x: ArrayLike,

        y: ArrayLike,

        ax: Any = 0,

        color: str = "black",

        alpha: float = 0.1,

        point_color: str | None = None,

        quad_as_tri_alpha: float = 0,

    ) -> None:
        pass

    @abstractmethod
    def lines(

        self,

        lines: LineReturn,

        line_type: LineType | str,

        ax: Any = 0,

        color: str = "C0",

        alpha: float = 1.0,

        linewidth: float = 1,

    ) -> None:
        pass

    @abstractmethod
    def mask(

        self,

        x: ArrayLike,

        y: ArrayLike,

        z: ArrayLike | np.ma.MaskedArray[Any, Any],

        ax: Any = 0,

        color: str = "black",

    ) -> None:
        pass

    @abstractmethod
    def save(self, filename: str, transparent: bool = False) -> None:
        pass

    @abstractmethod
    def save_to_buffer(self) -> io.BytesIO:
        pass

    @abstractmethod
    def show(self) -> None:
        pass

    @abstractmethod
    def title(self, title: str, ax: Any = 0, color: str | None = None) -> None:
        pass

    @abstractmethod
    def z_values(

        self,

        x: ArrayLike,

        y: ArrayLike,

        z: ArrayLike,

        ax: Any = 0,

        color: str = "green",

        fmt: str = ".1f",

        quad_as_tri: bool = False,

    ) -> None:
        pass