rsplotlib 0.1.9__cp313-cp313-win_amd64.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.
@@ -0,0 +1,2 @@
1
+ """rsplotlib.figure - 图形相关模块"""
2
+ from ._defaults import DEFAULT_DPI, DEFAULT_FIGSIZE # noqa: F401
@@ -0,0 +1,13 @@
1
+ """rsplotlib._figure_defaults - 图形创建相关的默认值
2
+
3
+ 集中管理 figure 尺寸、DPI 等默认值,避免散落在 pyplot 模块中。
4
+ 底层实现: Rust figure 模块
5
+ """
6
+
7
+ from .. import rsplotlib as _rs
8
+
9
+ # 默认图形尺寸(英寸),与 matplotlib 默认一致
10
+ DEFAULT_FIGSIZE = _rs.get_default_figsize()
11
+
12
+ # 默认 DPI
13
+ DEFAULT_DPI = _rs.get_default_dpi()
rsplotlib/gridspec.py ADDED
@@ -0,0 +1,6 @@
1
+ """rsplotlib.gridspec - 向后兼容的导入模块
2
+
3
+ 此模块提供从旧路径 `rsplotlib.gridspec` 导入的支持。
4
+ 实际实现在 `rsplotlib.layout.gridspec` 中。
5
+ """
6
+ from .layout.gridspec import * # noqa: F403, F401
@@ -0,0 +1,2 @@
1
+ """rsplotlib.layout - 布局管理"""
2
+ from . import gridspec # noqa: F401
@@ -0,0 +1,161 @@
1
+ """rsplotlib.gridspec - Matplotlib GridSpec 兼容接口
2
+
3
+ 提供子图网格布局管理。
4
+ 底层实现已迁移至 Rust 层,此模块为保持完整 Python 接口的薄包装层。
5
+ """
6
+
7
+ from .. import rsplotlib as _rs
8
+
9
+
10
+ class GridSpec:
11
+ """GridSpec 布局管理器
12
+
13
+ 用于在 Figure 中创建子图网格布局。
14
+ 底层实现: Rust GridSpec
15
+
16
+ Args:
17
+ nrows: 行数
18
+ ncols: 列数
19
+ left: 左边界 (0-1)
20
+ bottom: 下边界 (0-1)
21
+ right: 右边界 (0-1)
22
+ top: 上边界 (0-1)
23
+ wspace: 列间距
24
+ hspace: 行间距
25
+ width_ratios: 列宽比例
26
+ height_ratios: 行高比例
27
+ """
28
+
29
+ def __init__(self, nrows=1, ncols=1, left=None, bottom=None, right=None,
30
+ top=None, wspace=None, hspace=None, width_ratios=None,
31
+ height_ratios=None):
32
+ self.nrows = nrows
33
+ self.ncols = ncols
34
+ self.left = left
35
+ self.bottom = bottom
36
+ self.right = right
37
+ self.top = top
38
+ self.wspace = wspace
39
+ self.hspace = hspace
40
+ self.width_ratios = width_ratios or [1] * ncols
41
+ self.height_ratios = height_ratios or [1] * nrows
42
+ self._impl = _rs.GridSpec(nrows, ncols, left, bottom, right, top, wspace, hspace, width_ratios, height_ratios)
43
+
44
+ def __getitem__(self, key):
45
+ """支持 gs[row, col] 和 gs[row_start:row_end, col_start:col_end] 语法
46
+
47
+ 底层实现: Rust GridSpec.__getitem__
48
+
49
+ Returns:
50
+ SubplotSpec: 子图定位器
51
+ """
52
+ result = self._impl.__getitem__(key)
53
+ # 将 Rust SubplotSpec 包装为 Python SubplotSpec
54
+ return SubplotSpec._from_rust(result)
55
+
56
+ def get_subplot_params(self, figure=None):
57
+ """获取子图布局参数"""
58
+ return {
59
+ 'left': self.left,
60
+ 'bottom': self.bottom,
61
+ 'right': self.right,
62
+ 'top': self.top,
63
+ 'wspace': self.wspace,
64
+ 'hspace': self.hspace,
65
+ }
66
+
67
+ def tight_layout(self, figure=None, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
68
+ """自动调整布局"""
69
+ self._impl.tight_layout(figure, renderer)
70
+
71
+
72
+ class SubplotSpec:
73
+ """子图定位器
74
+
75
+ 底层实现: Rust SubplotSpec
76
+ """
77
+
78
+ def __init__(self, gridspec, row_start=0, row_end=1, col_start=0, col_end=1):
79
+ self.gridspec = gridspec
80
+ self.row_start = row_start
81
+ self.row_end = row_end
82
+ self.col_start = col_start
83
+ self.col_end = col_end
84
+ if gridspec is not None:
85
+ self.numRows = gridspec.nrows
86
+ self.numCols = gridspec.ncols
87
+ else:
88
+ self.numRows = max(row_end, 1)
89
+ self.numCols = max(col_end, 1)
90
+ self.rowStart = row_start
91
+ self.rowStop = row_end
92
+ self.colStart = col_start
93
+ self.colStop = col_end
94
+ # 创建 Rust 实现
95
+ if gridspec is not None:
96
+ self._impl = _rs.SubplotSpec(gridspec._impl, row_start, row_end, col_start, col_end)
97
+ else:
98
+ self._impl = _rs.SubplotSpec(None, row_start, row_end, col_start, col_end)
99
+
100
+ @classmethod
101
+ def _from_rust(cls, rust_spec):
102
+ """从 Rust SubplotSpec 创建 Python 包装"""
103
+ instance = cls.__new__(cls)
104
+ instance._impl = rust_spec
105
+ instance.numRows = rust_spec.numRows
106
+ instance.numCols = rust_spec.numCols
107
+ instance.rowStart = rust_spec.rowStart
108
+ instance.rowStop = rust_spec.rowStop
109
+ instance.colStart = rust_spec.colStart
110
+ instance.colStop = rust_spec.colStop
111
+ instance.row_start = rust_spec.rowStart
112
+ instance.row_end = rust_spec.rowStop
113
+ instance.col_start = rust_spec.colStart
114
+ instance.col_end = rust_spec.colStop
115
+ instance.gridspec = None # 简化处理
116
+ return instance
117
+
118
+ def get_position(self, figure):
119
+ """返回子图位置 (left, bottom, width, height)
120
+
121
+ 底层实现: Rust SubplotSpec.get_position
122
+ """
123
+ return self._impl.get_position(figure)
124
+
125
+ def get_grid_span(self):
126
+ """返回网格跨度"""
127
+ return (self.rowStart, self.rowStop, self.colStart, self.colStop)
128
+
129
+
130
+ # 便利函数
131
+ def GridSpecFromSubplotSpec(nrows, ncols, subplot_spec, **kwargs):
132
+ """从 SubplotSpec 创建 GridSpec"""
133
+ from ..rsplotlib import gridspec_from_subplotspec
134
+ # 参数提取
135
+ left = kwargs.get('left')
136
+ bottom = kwargs.get('bottom')
137
+ right = kwargs.get('right')
138
+ top = kwargs.get('top')
139
+ wspace = kwargs.get('wspace')
140
+ hspace = kwargs.get('hspace')
141
+ width_ratios = kwargs.get('width_ratios')
142
+ height_ratios = kwargs.get('height_ratios')
143
+ rust_gs = gridspec_from_subplotspec(
144
+ nrows, ncols, left=left, bottom=bottom, right=right, top=top,
145
+ wspace=wspace, hspace=hspace, width_ratios=width_ratios,
146
+ height_ratios=height_ratios,
147
+ )
148
+ # 包装为 Python GridSpec
149
+ gs = GridSpec.__new__(GridSpec)
150
+ gs.nrows = nrows
151
+ gs.ncols = ncols
152
+ gs.left = left
153
+ gs.bottom = bottom
154
+ gs.right = right
155
+ gs.top = top
156
+ gs.wspace = wspace
157
+ gs.hspace = hspace
158
+ gs.width_ratios = width_ratios or [1] * ncols
159
+ gs.height_ratios = height_ratios or [1] * nrows
160
+ gs._impl = rust_gs
161
+ return gs
rsplotlib/pylab.py ADDED
@@ -0,0 +1,22 @@
1
+ """rsplotlib.pylab - Matplotlib pylab 兼容接口"""
2
+
3
+ from .utils._rcparams import rcParams, rcParamsOrig
4
+
5
+ # mpl 模块可以从 pylab 导入
6
+
7
+
8
+ class MplModule:
9
+ """兼容 matplotlib 的 mpl 模块"""
10
+
11
+ def __init__(self):
12
+ self.rcParams = rcParams
13
+ self.rcParamsOrig = rcParamsOrig
14
+
15
+ def get_backend(self):
16
+ return 'Agg'
17
+
18
+ def set_backend(self, backend):
19
+ pass
20
+
21
+
22
+ mpl = MplModule()