anyplotlib 0.1.0__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.
Files changed (42) hide show
  1. anyplotlib/__init__.py +53 -0
  2. anyplotlib/_base_plot.py +229 -0
  3. anyplotlib/_electron.py +74 -0
  4. anyplotlib/_repr_utils.py +345 -0
  5. anyplotlib/_utils.py +194 -0
  6. anyplotlib/axes/__init__.py +6 -0
  7. anyplotlib/axes/_axes.py +510 -0
  8. anyplotlib/axes/_inset_axes.py +126 -0
  9. anyplotlib/callbacks.py +328 -0
  10. anyplotlib/embed.py +194 -0
  11. anyplotlib/figure/__init__.py +7 -0
  12. anyplotlib/figure/_figure.py +633 -0
  13. anyplotlib/figure/_gridspec.py +99 -0
  14. anyplotlib/figure/_subplots.py +100 -0
  15. anyplotlib/figure_esm.js +6011 -0
  16. anyplotlib/markers.py +704 -0
  17. anyplotlib/plot1d/__init__.py +6 -0
  18. anyplotlib/plot1d/_plot1d.py +1376 -0
  19. anyplotlib/plot1d/_plotbar.py +436 -0
  20. anyplotlib/plot2d/__init__.py +5 -0
  21. anyplotlib/plot2d/_plot2d.py +726 -0
  22. anyplotlib/plot2d/_plotmesh.py +116 -0
  23. anyplotlib/plot3d/__init__.py +4 -0
  24. anyplotlib/plot3d/_plot3d.py +524 -0
  25. anyplotlib/plotxy/__init__.py +4 -0
  26. anyplotlib/plotxy/_plotxy.py +273 -0
  27. anyplotlib/sphinx_anywidget/__init__.py +177 -0
  28. anyplotlib/sphinx_anywidget/_directive.py +245 -0
  29. anyplotlib/sphinx_anywidget/_repr_utils.py +298 -0
  30. anyplotlib/sphinx_anywidget/_scraper.py +390 -0
  31. anyplotlib/sphinx_anywidget/_wheel_builder.py +84 -0
  32. anyplotlib/sphinx_anywidget/static/anywidget_bridge.js +1099 -0
  33. anyplotlib/sphinx_anywidget/static/anywidget_overlay.css +100 -0
  34. anyplotlib/widgets/__init__.py +18 -0
  35. anyplotlib/widgets/_base.py +218 -0
  36. anyplotlib/widgets/_widgets1d.py +109 -0
  37. anyplotlib/widgets/_widgets2d.py +141 -0
  38. anyplotlib/widgets/_widgets3d.py +50 -0
  39. anyplotlib-0.1.0.dist-info/METADATA +160 -0
  40. anyplotlib-0.1.0.dist-info/RECORD +42 -0
  41. anyplotlib-0.1.0.dist-info/WHEEL +4 -0
  42. anyplotlib-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,99 @@
1
+ """
2
+ figure/_gridspec.py
3
+ ===================
4
+ Grid layout descriptors: GridSpec and SubplotSpec.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+
10
+ class SubplotSpec:
11
+ """Describes which grid cells a subplot occupies."""
12
+
13
+ def __init__(self, gs: "GridSpec", row_start: int, row_stop: int,
14
+ col_start: int, col_stop: int):
15
+ self._gs = gs
16
+ self.row_start = row_start
17
+ self.row_stop = row_stop
18
+ self.col_start = col_start
19
+ self.col_stop = col_stop
20
+
21
+ def __repr__(self) -> str:
22
+ return (f"SubplotSpec(rows={self.row_start}:{self.row_stop}, "
23
+ f"cols={self.col_start}:{self.col_stop})")
24
+
25
+
26
+ class GridSpec:
27
+ """Define a grid of subplot cells.
28
+
29
+ Parameters
30
+ ----------
31
+ nrows, ncols : int
32
+ Grid dimensions.
33
+ width_ratios : list of float, optional
34
+ Relative column widths (length ncols). Defaults to equal widths.
35
+ height_ratios : list of float, optional
36
+ Relative row heights (length nrows). Defaults to equal heights.
37
+
38
+ Examples
39
+ --------
40
+ >>> gs = GridSpec(2, 3, width_ratios=[2, 1, 1])
41
+ >>> spec = gs[0, :] # top row spanning all columns
42
+ >>> spec = gs[1, 1:3] # bottom-right 2 columns
43
+ """
44
+
45
+ def __init__(self, nrows: int, ncols: int, *,
46
+ width_ratios: list | None = None,
47
+ height_ratios: list | None = None):
48
+ self.nrows = nrows
49
+ self.ncols = ncols
50
+ self.width_ratios = list(width_ratios) if width_ratios else [1] * ncols
51
+ self.height_ratios = list(height_ratios) if height_ratios else [1] * nrows
52
+ if len(self.width_ratios) != ncols:
53
+ raise ValueError("len(width_ratios) must equal ncols")
54
+ if len(self.height_ratios) != nrows:
55
+ raise ValueError("len(height_ratios) must equal nrows")
56
+
57
+ def __getitem__(self, key) -> SubplotSpec:
58
+ """Return a SubplotSpec for the given (row, col) index or slice pair.
59
+
60
+ Matches matplotlib's GridSpec indexing exactly:
61
+ - Integer index ``i`` selects a single row or column (negative indices
62
+ count from the end, just like Python lists).
63
+ - Slice ``start:stop`` selects rows/columns ``start`` up to (but not
64
+ including) ``stop``. The full-span slice ``:`` selects all rows or
65
+ columns.
66
+ - Step values other than 1 (or None) raise ``ValueError``.
67
+ - Out-of-range or empty slices raise ``IndexError``.
68
+ """
69
+ if not isinstance(key, tuple) or len(key) != 2:
70
+ raise IndexError("GridSpec requires a (row, col) index or slice pair")
71
+ row_idx, col_idx = key
72
+
73
+ def _resolve(idx, n, axis_name):
74
+ if isinstance(idx, int):
75
+ i = idx if idx >= 0 else n + idx
76
+ if not (0 <= i < n):
77
+ raise IndexError(
78
+ f"{axis_name} index {idx} is out of bounds for size {n}"
79
+ )
80
+ return i, i + 1
81
+ if isinstance(idx, slice):
82
+ start, stop, step = idx.indices(n)
83
+ if step != 1:
84
+ raise ValueError(
85
+ f"GridSpec slices must have step 1 (got {step})"
86
+ )
87
+ if start >= stop:
88
+ raise IndexError(
89
+ f"GridSpec slice {idx} produces an empty span on axis of size {n}"
90
+ )
91
+ return start, stop
92
+ raise IndexError(f"Invalid GridSpec index: {idx!r}")
93
+
94
+ r0, r1 = _resolve(row_idx, self.nrows, "row")
95
+ c0, c1 = _resolve(col_idx, self.ncols, "col")
96
+ return SubplotSpec(self, r0, r1, c0, c1)
97
+
98
+ def __repr__(self) -> str:
99
+ return f"GridSpec({self.nrows}, {self.ncols})"
@@ -0,0 +1,100 @@
1
+ """
2
+ figure/_subplots.py
3
+ ===================
4
+ Factory function mirroring matplotlib.pyplot.subplots.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import numpy as np
10
+
11
+ from anyplotlib.figure._figure import Figure
12
+ from anyplotlib.figure._gridspec import GridSpec
13
+
14
+
15
+ def subplots(nrows=1, ncols=1, *,
16
+ sharex=False, sharey=False,
17
+ figsize=(640, 480),
18
+ width_ratios=None,
19
+ height_ratios=None,
20
+ gridspec_kw=None,
21
+ display_stats=False,
22
+ help=""):
23
+ """Create a :class:`Figure` and a grid of :class:`~anyplotlib.axes.Axes`.
24
+
25
+ Mirrors :func:`matplotlib.pyplot.subplots`.
26
+
27
+ Parameters
28
+ ----------
29
+ nrows, ncols : int
30
+ Number of rows and columns in the grid.
31
+ sharex, sharey : bool
32
+ Link pan/zoom across all panels on the respective axis.
33
+ figsize : (width, height)
34
+ Figure size in CSS pixels. Default ``(640, 480)``.
35
+ width_ratios : list of float, optional
36
+ Relative column widths. Equivalent to
37
+ ``gridspec_kw={"width_ratios": ...}``.
38
+ height_ratios : list of float, optional
39
+ Relative row heights. Equivalent to
40
+ ``gridspec_kw={"height_ratios": ...}``.
41
+ gridspec_kw : dict, optional
42
+ Extra keyword arguments forwarded to :class:`GridSpec`.
43
+ Recognised keys: ``width_ratios``, ``height_ratios``.
44
+ display_stats : bool, optional
45
+ Show per-panel FPS / frame-time overlay. Default False.
46
+ help : str, optional
47
+ Help text shown when the user clicks the **?** badge on the figure.
48
+ Newlines (``\\n``) create separate lines in the card. The badge is
49
+ hidden when *help* is empty (default). Suppressed globally when
50
+ ``apl.show_help = False``.
51
+
52
+ Returns
53
+ -------
54
+ fig : Figure
55
+ axs : Axes or numpy array of Axes
56
+ - Single cell → scalar ``Axes``.
57
+ - Single row → 1-D array of shape ``(ncols,)``.
58
+ - Single column → 1-D array of shape ``(nrows,)``.
59
+ - Otherwise → 2-D array of shape ``(nrows, ncols)``.
60
+
61
+ Examples
62
+ --------
63
+ >>> import anyplotlib as apl
64
+ >>> import numpy as np
65
+ >>> fig, axs = apl.subplots(2, 1, figsize=(640, 600))
66
+ >>> v2d = axs[0].imshow(np.random.rand(128, 128))
67
+ >>> v1d = axs[1].plot(np.sin(np.linspace(0, 6.28, 256)))
68
+ >>> fig
69
+ """
70
+ # Merge gridspec_kw into width_ratios / height_ratios (matplotlib compat)
71
+ if gridspec_kw:
72
+ width_ratios = gridspec_kw.get("width_ratios", width_ratios)
73
+ height_ratios = gridspec_kw.get("height_ratios", height_ratios)
74
+
75
+ fig = Figure(
76
+ nrows=nrows, ncols=ncols, figsize=figsize,
77
+ width_ratios=width_ratios, height_ratios=height_ratios,
78
+ sharex=sharex, sharey=sharey,
79
+ display_stats=display_stats,
80
+ help=help,
81
+ )
82
+ # Build the GridSpec from the Figure's own stored ratios so there is
83
+ # exactly one source of truth.
84
+ gs = GridSpec(
85
+ nrows, ncols,
86
+ width_ratios=fig._width_ratios,
87
+ height_ratios=fig._height_ratios,
88
+ )
89
+ axes_grid = np.empty((nrows, ncols), dtype=object)
90
+ for r in range(nrows):
91
+ for c in range(ncols):
92
+ axes_grid[r, c] = fig.add_subplot(gs[r, c])
93
+
94
+ if nrows == 1 and ncols == 1:
95
+ return fig, axes_grid[0, 0]
96
+ if nrows == 1:
97
+ return fig, axes_grid[0, :]
98
+ if ncols == 1:
99
+ return fig, axes_grid[:, 0]
100
+ return fig, axes_grid