adopt-plot 0.0.3__tar.gz → 0.0.5__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.
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: adopt-plot
3
+ Version: 0.0.5
4
+ Summary: A universal plotter for implicit functions using adaptive engine selection.
5
+ Author: VartRusData
6
+ License: BSD 3-Clause
7
+ Classifier: License :: OSI Approved :: BSD License
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: sympy
12
+ Requires-Dist: matplotlib
13
+ Requires-Dist: numpy
14
+ Dynamic: license-file
15
+
16
+ # adopt-plot
17
+
18
+ A library for plotting implicit functions using two rendering engines:
19
+
20
+ - `contour` from `matplotlib`.
21
+ - `plot_implicit` which internally uses **Adaptive Marching Squares (AMR)** — an adaptive algorithm that correctly handles the domain of definition and discontinuities.
22
+
23
+ **Automatic selection:** If the equation has domain restrictions (e.g., logarithm or square root), `plot_implicit` is used. If the function is smooth, the fast `contour` engine is chosen. Visually, they are indistinguishable, but the best algorithm is selected automatically.
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install adopt-plot
31
+ ```
32
+ ## Quick Start
33
+ Plot a graph in one line:
34
+
35
+ ```python
36
+ from adopt_plot import AdoptPlot
37
+
38
+ # The plot will open immediately
39
+ plot = AdoptPlot("y = 2*x + 2")
40
+ ```
41
+ Or with deferred display (to add custom elements first):
42
+
43
+ ```python
44
+ from adopt_plot import AdoptPlot
45
+
46
+ plot = AdoptPlot("y = 1/x", show=False)
47
+ # Add custom elements here:
48
+ plot.ax.scatter(2, 2, color='red')
49
+ plot.show()
50
+ # Show the plot after modifications
51
+ ```
52
+ All plot elements (`axes`, `fig`, `plt`) are accessible via the plot object and its attributes:
53
+
54
+ ```python
55
+ from adopt_plot import AdoptPlot
56
+ plot = AdoptPlot("y = 1/x", show=False)
57
+ plot.ax.set_xlim(-10, 10) # Change X-axis limits
58
+ plot.fig.savefig("my_plot.png", dpi=300)# Save to file
59
+ ```
60
+ ![my_plot](https://i.yapx.ru/eCFD2.png)
61
+ ```python
62
+ from adopt_plot import AdoptPlot
63
+
64
+ plot = AdoptPlot("sin(sqrt(x**2 + y**2)) / log(x**2 + y**2 + 1) = 0", show=False)
65
+
66
+ # Подкручиваем стиль под публикацию
67
+ plot.ax.set_title("Implicit function with radial oscillations")
68
+ plot.ax.grid(True, linestyle=':', alpha=0.5)
69
+
70
+ # Сохраняем с высоким DPI
71
+ plot.fig.savefig("publication_ready.png", dpi=300, bbox_inches='tight')
72
+ plot.show()
73
+ ```
74
+ ![Сложная функция](https://i.yapx.ru/eCFBo.png) Сложная функция построенная через AdoptPlot
75
+
76
+ ## Parameters
77
+
78
+ When creating an `AdoptPlot` object, the following parameters are available:
79
+
80
+ - **`expr`** (`str`): The equation string (e.g., `"y = 1/x"`).
81
+ - **`lib`** (`Literal['contour', 'implicit', None]`): Forced rendering engine. Default is `None` (automatic selection).
82
+ - **`xlims`, `ylims`** (`Tuple[float, float]`): Initial visible range for the plot. Default `(-20, 20)`.
83
+ - **`n`** (`int`): Grid density for the `contour` engine. Default `10000`.
84
+ - **`depth`** (`int`): Adaptive refinement depth for `plot_implicit`. Default `9`.
85
+ - **`linewidth`** (`float`): Thickness of the plot line. Default `2.0`.
86
+ - **`limit`** (`float | Tuple[float, float, float, float]`): Computational domain. Pass a single number (square) or a tuple of 4 numbers `(x_min, x_max, y_min, y_max)`. Default `100`.
87
+ - **`color`** (`str`): Line color. Default `'blue'`.
88
+ - **`legend`** (`bool`): Whether to display the legend. Default `True`.
89
+ - **`points`** (`bool`): Whether to display axis intersection points. Default `True`.
90
+ - **`grid`** (`bool`): Whether to display the grid. Default `True`.
91
+ - **`interact`** (`bool`): Allow zooming and panning via keyboard (`Ctrl +` and `Ctrl -`). Default `True`.
92
+ - **`show`** (`bool`): If `False`, the plot does not open immediately, allowing you to add elements. Default `True`.
93
+ - **`text_legend`** (`str`): Additional text for the legend. Default `None`.
94
+ ## License
95
+
96
+ Distributed under the **BSD 3-Clause** license.
@@ -0,0 +1,81 @@
1
+ # adopt-plot
2
+
3
+ A library for plotting implicit functions using two rendering engines:
4
+
5
+ - `contour` from `matplotlib`.
6
+ - `plot_implicit` which internally uses **Adaptive Marching Squares (AMR)** — an adaptive algorithm that correctly handles the domain of definition and discontinuities.
7
+
8
+ **Automatic selection:** If the equation has domain restrictions (e.g., logarithm or square root), `plot_implicit` is used. If the function is smooth, the fast `contour` engine is chosen. Visually, they are indistinguishable, but the best algorithm is selected automatically.
9
+
10
+ ---
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install adopt-plot
16
+ ```
17
+ ## Quick Start
18
+ Plot a graph in one line:
19
+
20
+ ```python
21
+ from adopt_plot import AdoptPlot
22
+
23
+ # The plot will open immediately
24
+ plot = AdoptPlot("y = 2*x + 2")
25
+ ```
26
+ Or with deferred display (to add custom elements first):
27
+
28
+ ```python
29
+ from adopt_plot import AdoptPlot
30
+
31
+ plot = AdoptPlot("y = 1/x", show=False)
32
+ # Add custom elements here:
33
+ plot.ax.scatter(2, 2, color='red')
34
+ plot.show()
35
+ # Show the plot after modifications
36
+ ```
37
+ All plot elements (`axes`, `fig`, `plt`) are accessible via the plot object and its attributes:
38
+
39
+ ```python
40
+ from adopt_plot import AdoptPlot
41
+ plot = AdoptPlot("y = 1/x", show=False)
42
+ plot.ax.set_xlim(-10, 10) # Change X-axis limits
43
+ plot.fig.savefig("my_plot.png", dpi=300)# Save to file
44
+ ```
45
+ ![my_plot](https://i.yapx.ru/eCFD2.png)
46
+ ```python
47
+ from adopt_plot import AdoptPlot
48
+
49
+ plot = AdoptPlot("sin(sqrt(x**2 + y**2)) / log(x**2 + y**2 + 1) = 0", show=False)
50
+
51
+ # Подкручиваем стиль под публикацию
52
+ plot.ax.set_title("Implicit function with radial oscillations")
53
+ plot.ax.grid(True, linestyle=':', alpha=0.5)
54
+
55
+ # Сохраняем с высоким DPI
56
+ plot.fig.savefig("publication_ready.png", dpi=300, bbox_inches='tight')
57
+ plot.show()
58
+ ```
59
+ ![Сложная функция](https://i.yapx.ru/eCFBo.png) Сложная функция построенная через AdoptPlot
60
+
61
+ ## Parameters
62
+
63
+ When creating an `AdoptPlot` object, the following parameters are available:
64
+
65
+ - **`expr`** (`str`): The equation string (e.g., `"y = 1/x"`).
66
+ - **`lib`** (`Literal['contour', 'implicit', None]`): Forced rendering engine. Default is `None` (automatic selection).
67
+ - **`xlims`, `ylims`** (`Tuple[float, float]`): Initial visible range for the plot. Default `(-20, 20)`.
68
+ - **`n`** (`int`): Grid density for the `contour` engine. Default `10000`.
69
+ - **`depth`** (`int`): Adaptive refinement depth for `plot_implicit`. Default `9`.
70
+ - **`linewidth`** (`float`): Thickness of the plot line. Default `2.0`.
71
+ - **`limit`** (`float | Tuple[float, float, float, float]`): Computational domain. Pass a single number (square) or a tuple of 4 numbers `(x_min, x_max, y_min, y_max)`. Default `100`.
72
+ - **`color`** (`str`): Line color. Default `'blue'`.
73
+ - **`legend`** (`bool`): Whether to display the legend. Default `True`.
74
+ - **`points`** (`bool`): Whether to display axis intersection points. Default `True`.
75
+ - **`grid`** (`bool`): Whether to display the grid. Default `True`.
76
+ - **`interact`** (`bool`): Allow zooming and panning via keyboard (`Ctrl +` and `Ctrl -`). Default `True`.
77
+ - **`show`** (`bool`): If `False`, the plot does not open immediately, allowing you to add elements. Default `True`.
78
+ - **`text_legend`** (`str`): Additional text for the legend. Default `None`.
79
+ ## License
80
+
81
+ Distributed under the **BSD 3-Clause** license.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "adopt-plot"
7
- version = "0.0.3"
7
+ version = "0.0.5"
8
8
  description = "A universal plotter for implicit functions using adaptive engine selection."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -20,4 +20,8 @@ classifiers = [
20
20
  ]
21
21
  [tool.setuptools]
22
22
  packages = ["adopt_plot"]
23
- package-dir = {"" = "src"}
23
+ package-dir = {"" = "src"}
24
+
25
+ [tool.pytest.ini_options]
26
+ testpaths = ["tests", "."] # <-- точка "." означает "ищи также в корне"
27
+ python_files = ["test_*.py", "*_test.py", "test.py"]
@@ -75,7 +75,7 @@ def insert_multiplication_signs(expr: str, extra_functions=None) -> str:
75
75
 
76
76
  from typing import Literal, Optional, Tuple
77
77
 
78
- class AdoptPlot():
78
+ class AdoptPlot:
79
79
  def __init__(self,
80
80
  expr: str,
81
81
  lib: Literal['contour', 'implicit', None] = None,
@@ -260,8 +260,9 @@ class AdoptPlot():
260
260
  # Принудительно перерисовываем график
261
261
  event.canvas.draw_idle()
262
262
  # === 2. Увеличиваем разрешение для гладкости (было 500, стало 1000) ===
263
- if self.lib == 'implicit' or (has_odz and self.lib is None):
263
+ if self.lib == 'implicit' or (has_odz(expr, var1) and self.lib is None):
264
264
  from sympy.plotting import plot_implicit
265
+ self.current_engine = 'implicit'
265
266
  if isinstance(self.limit, (int, float)):
266
267
  self.p = plot_implicit(self.eq, (var1, -self.limit, self.limit), (var2, -self.limit, self.limit), show=False, n=self.n, depth=self.depth, line_color=self.color)
267
268
  elif isinstance(self.limit, tuple):
@@ -347,6 +348,7 @@ class AdoptPlot():
347
348
 
348
349
  return
349
350
  else:
351
+ self.current_engine = 'contour'
350
352
  if isinstance(self.limit, (float, int)):
351
353
 
352
354
  x_vals = np.linspace(-self.limit, self.limit, self.n)
@@ -366,6 +368,8 @@ class AdoptPlot():
366
368
  Z = f(X, Y)
367
369
  # print(Z)
368
370
  self.fig, self.ax = plt.subplots()
371
+ if self.interact:
372
+ self.fig.canvas.mpl_connect('key_press_event', zoom_key_handler)
369
373
  x_coords_str = ", ".join([f"({x:.2f}, 0)" for x in x_intercepts]) if x_intercepts else "Нет"
370
374
  y_coords_str = ", ".join([f"(0, {y:.2f})" for y in y_intercepts]) if y_intercepts else "Нет"
371
375
  self.ax.contour(X, Y, Z, levels=[0], colors=self.color, linewidths=self.linewidth)
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: adopt-plot
3
+ Version: 0.0.5
4
+ Summary: A universal plotter for implicit functions using adaptive engine selection.
5
+ Author: VartRusData
6
+ License: BSD 3-Clause
7
+ Classifier: License :: OSI Approved :: BSD License
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: sympy
12
+ Requires-Dist: matplotlib
13
+ Requires-Dist: numpy
14
+ Dynamic: license-file
15
+
16
+ # adopt-plot
17
+
18
+ A library for plotting implicit functions using two rendering engines:
19
+
20
+ - `contour` from `matplotlib`.
21
+ - `plot_implicit` which internally uses **Adaptive Marching Squares (AMR)** — an adaptive algorithm that correctly handles the domain of definition and discontinuities.
22
+
23
+ **Automatic selection:** If the equation has domain restrictions (e.g., logarithm or square root), `plot_implicit` is used. If the function is smooth, the fast `contour` engine is chosen. Visually, they are indistinguishable, but the best algorithm is selected automatically.
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install adopt-plot
31
+ ```
32
+ ## Quick Start
33
+ Plot a graph in one line:
34
+
35
+ ```python
36
+ from adopt_plot import AdoptPlot
37
+
38
+ # The plot will open immediately
39
+ plot = AdoptPlot("y = 2*x + 2")
40
+ ```
41
+ Or with deferred display (to add custom elements first):
42
+
43
+ ```python
44
+ from adopt_plot import AdoptPlot
45
+
46
+ plot = AdoptPlot("y = 1/x", show=False)
47
+ # Add custom elements here:
48
+ plot.ax.scatter(2, 2, color='red')
49
+ plot.show()
50
+ # Show the plot after modifications
51
+ ```
52
+ All plot elements (`axes`, `fig`, `plt`) are accessible via the plot object and its attributes:
53
+
54
+ ```python
55
+ from adopt_plot import AdoptPlot
56
+ plot = AdoptPlot("y = 1/x", show=False)
57
+ plot.ax.set_xlim(-10, 10) # Change X-axis limits
58
+ plot.fig.savefig("my_plot.png", dpi=300)# Save to file
59
+ ```
60
+ ![my_plot](https://i.yapx.ru/eCFD2.png)
61
+ ```python
62
+ from adopt_plot import AdoptPlot
63
+
64
+ plot = AdoptPlot("sin(sqrt(x**2 + y**2)) / log(x**2 + y**2 + 1) = 0", show=False)
65
+
66
+ # Подкручиваем стиль под публикацию
67
+ plot.ax.set_title("Implicit function with radial oscillations")
68
+ plot.ax.grid(True, linestyle=':', alpha=0.5)
69
+
70
+ # Сохраняем с высоким DPI
71
+ plot.fig.savefig("publication_ready.png", dpi=300, bbox_inches='tight')
72
+ plot.show()
73
+ ```
74
+ ![Сложная функция](https://i.yapx.ru/eCFBo.png) Сложная функция построенная через AdoptPlot
75
+
76
+ ## Parameters
77
+
78
+ When creating an `AdoptPlot` object, the following parameters are available:
79
+
80
+ - **`expr`** (`str`): The equation string (e.g., `"y = 1/x"`).
81
+ - **`lib`** (`Literal['contour', 'implicit', None]`): Forced rendering engine. Default is `None` (automatic selection).
82
+ - **`xlims`, `ylims`** (`Tuple[float, float]`): Initial visible range for the plot. Default `(-20, 20)`.
83
+ - **`n`** (`int`): Grid density for the `contour` engine. Default `10000`.
84
+ - **`depth`** (`int`): Adaptive refinement depth for `plot_implicit`. Default `9`.
85
+ - **`linewidth`** (`float`): Thickness of the plot line. Default `2.0`.
86
+ - **`limit`** (`float | Tuple[float, float, float, float]`): Computational domain. Pass a single number (square) or a tuple of 4 numbers `(x_min, x_max, y_min, y_max)`. Default `100`.
87
+ - **`color`** (`str`): Line color. Default `'blue'`.
88
+ - **`legend`** (`bool`): Whether to display the legend. Default `True`.
89
+ - **`points`** (`bool`): Whether to display axis intersection points. Default `True`.
90
+ - **`grid`** (`bool`): Whether to display the grid. Default `True`.
91
+ - **`interact`** (`bool`): Allow zooming and panning via keyboard (`Ctrl +` and `Ctrl -`). Default `True`.
92
+ - **`show`** (`bool`): If `False`, the plot does not open immediately, allowing you to add elements. Default `True`.
93
+ - **`text_legend`** (`str`): Additional text for the legend. Default `None`.
94
+ ## License
95
+
96
+ Distributed under the **BSD 3-Clause** license.
adopt_plot-0.0.3/PKG-INFO DELETED
@@ -1,19 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: adopt-plot
3
- Version: 0.0.3
4
- Summary: A universal plotter for implicit functions using adaptive engine selection.
5
- Author: VartRusData
6
- License: BSD 3-Clause
7
- Classifier: License :: OSI Approved :: BSD License
8
- Requires-Python: >=3.9
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: sympy
12
- Requires-Dist: matplotlib
13
- Requires-Dist: numpy
14
- Dynamic: license-file
15
-
16
- # adopt-plot
17
-
18
- A simple Python library for plotting implicit functions with adaptive engine selection.
19
- Just pass an equation and get a beautiful, mathematically correct plot.
@@ -1,4 +0,0 @@
1
- # adopt-plot
2
-
3
- A simple Python library for plotting implicit functions with adaptive engine selection.
4
- Just pass an equation and get a beautiful, mathematically correct plot.
@@ -1,19 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: adopt-plot
3
- Version: 0.0.3
4
- Summary: A universal plotter for implicit functions using adaptive engine selection.
5
- Author: VartRusData
6
- License: BSD 3-Clause
7
- Classifier: License :: OSI Approved :: BSD License
8
- Requires-Python: >=3.9
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: sympy
12
- Requires-Dist: matplotlib
13
- Requires-Dist: numpy
14
- Dynamic: license-file
15
-
16
- # adopt-plot
17
-
18
- A simple Python library for plotting implicit functions with adaptive engine selection.
19
- Just pass an equation and get a beautiful, mathematically correct plot.
File without changes
File without changes