staplot 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.
- staplot/__init__.py +1 -0
- staplot/api.py +441 -0
- staplot/main.py +21 -0
- staplot/models/__init__.py +1 -0
- staplot/models/project.py +461 -0
- staplot/plots/__init__.py +14 -0
- staplot/plots/bar.py +104 -0
- staplot/plots/before_after.py +110 -0
- staplot/plots/bland_altman.py +73 -0
- staplot/plots/box.py +95 -0
- staplot/plots/distribution_plot.py +188 -0
- staplot/plots/grouped_bar.py +112 -0
- staplot/plots/heatmap.py +73 -0
- staplot/plots/histogram.py +76 -0
- staplot/plots/qq.py +61 -0
- staplot/plots/residuals.py +72 -0
- staplot/plots/roc_plot.py +40 -0
- staplot/plots/scatter.py +61 -0
- staplot/plots/significance.py +94 -0
- staplot/plots/styles.py +154 -0
- staplot/plots/survival.py +78 -0
- staplot/plots/volcano.py +110 -0
- staplot/stats/__init__.py +15 -0
- staplot/stats/anova.py +124 -0
- staplot/stats/chi_square.py +85 -0
- staplot/stats/correlation.py +71 -0
- staplot/stats/curve_fit.py +85 -0
- staplot/stats/descriptive.py +52 -0
- staplot/stats/distribution.py +223 -0
- staplot/stats/multiple_comparisons.py +104 -0
- staplot/stats/normality.py +67 -0
- staplot/stats/outliers.py +62 -0
- staplot/stats/power.py +130 -0
- staplot/stats/regression.py +95 -0
- staplot/stats/repeated_measures.py +114 -0
- staplot/stats/roc.py +196 -0
- staplot/stats/tests.py +142 -0
- staplot/stats/two_way_anova.py +88 -0
- staplot/ui/__init__.py +0 -0
- staplot/ui/analysis_dialog.py +406 -0
- staplot/ui/axis_dialog.py +104 -0
- staplot/ui/computed_column_dialog.py +261 -0
- staplot/ui/contingency_table_widget.py +158 -0
- staplot/ui/data_table_widget.py +277 -0
- staplot/ui/distribution_inspector.py +431 -0
- staplot/ui/figure_layout_widget.py +236 -0
- staplot/ui/graph_gallery.py +117 -0
- staplot/ui/graph_options_dialog.py +325 -0
- staplot/ui/grouped_table_widget.py +190 -0
- staplot/ui/layout_dialog.py +218 -0
- staplot/ui/main_window.py +1126 -0
- staplot/ui/multiple_comparisons_dialog.py +168 -0
- staplot/ui/navigator.py +88 -0
- staplot/ui/plot_canvas.py +251 -0
- staplot/ui/power_dialog.py +108 -0
- staplot/ui/report_dialog.py +255 -0
- staplot/ui/reshape_dialog.py +286 -0
- staplot/ui/results_widget.py +19 -0
- staplot/ui/standard_curve_dialog.py +150 -0
- staplot/ui/test_wizard.py +252 -0
- staplot/ui/transform_dialog.py +137 -0
- staplot/ui/undo_commands.py +86 -0
- staplot-0.1.0.dist-info/METADATA +85 -0
- staplot-0.1.0.dist-info/RECORD +68 -0
- staplot-0.1.0.dist-info/WHEEL +5 -0
- staplot-0.1.0.dist-info/entry_points.txt +2 -0
- staplot-0.1.0.dist-info/licenses/LICENSE +24 -0
- staplot-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"""Figure Layout / Panel builder — arrange multiple graphs into one export-ready figure."""
|
|
2
|
+
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
|
|
5
|
+
import matplotlib.image as mpimg
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
import matplotlib.figure
|
|
8
|
+
|
|
9
|
+
from qtpy.QtWidgets import (
|
|
10
|
+
QDialog, QVBoxLayout, QHBoxLayout, QListWidget, QAbstractItemView,
|
|
11
|
+
QPushButton, QLabel, QSpinBox, QFileDialog, QGroupBox, QFormLayout,
|
|
12
|
+
QComboBox, QDoubleSpinBox,
|
|
13
|
+
)
|
|
14
|
+
from qtpy.QtCore import Qt
|
|
15
|
+
|
|
16
|
+
from ..plots import styles
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ── helpers ──────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@styles.styled
|
|
23
|
+
def _fig_to_img(fig: matplotlib.figure.Figure, dpi: int = 120) -> "numpy array":
|
|
24
|
+
"""Render a Figure to an RGBA numpy array via PNG."""
|
|
25
|
+
buf = BytesIO()
|
|
26
|
+
fig.savefig(buf, format="png", dpi=dpi, bbox_inches="tight")
|
|
27
|
+
buf.seek(0)
|
|
28
|
+
return mpimg.imread(buf)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@styles.styled
|
|
32
|
+
def build_panel_figure(
|
|
33
|
+
gcs,
|
|
34
|
+
render_fn,
|
|
35
|
+
nrows: int,
|
|
36
|
+
ncols: int,
|
|
37
|
+
dpi: int = 120,
|
|
38
|
+
fig_width: float | None = None,
|
|
39
|
+
fig_height: float | None = None,
|
|
40
|
+
label_panels: bool = True,
|
|
41
|
+
) -> matplotlib.figure.Figure:
|
|
42
|
+
"""
|
|
43
|
+
Render each GraphConfig in *gcs* into a nrows×ncols panel.
|
|
44
|
+
|
|
45
|
+
render_fn(gc) → matplotlib Figure | None
|
|
46
|
+
|
|
47
|
+
Panels are rasterised at *dpi* and composited via imshow — fast and reliable
|
|
48
|
+
across all plot types. For print-quality output, use dpi >= 200.
|
|
49
|
+
"""
|
|
50
|
+
import numpy as np
|
|
51
|
+
|
|
52
|
+
n_panels = min(len(gcs), nrows * ncols)
|
|
53
|
+
w = fig_width or ncols * 4.2
|
|
54
|
+
h = fig_height or nrows * 3.6
|
|
55
|
+
panel_fig = plt.figure(figsize=(w, h))
|
|
56
|
+
|
|
57
|
+
for idx in range(n_panels):
|
|
58
|
+
gc = gcs[idx]
|
|
59
|
+
ax = panel_fig.add_subplot(nrows, ncols, idx + 1)
|
|
60
|
+
try:
|
|
61
|
+
sub = render_fn(gc)
|
|
62
|
+
if sub is None:
|
|
63
|
+
raise RuntimeError("render returned None")
|
|
64
|
+
img = _fig_to_img(sub, dpi=dpi)
|
|
65
|
+
ax.imshow(img, aspect="equal", interpolation="lanczos")
|
|
66
|
+
except Exception as exc:
|
|
67
|
+
ax.text(0.5, 0.5, f"[error]\n{exc}", ha="center", va="center",
|
|
68
|
+
transform=ax.transAxes, fontsize=8, color="red")
|
|
69
|
+
ax.axis("off")
|
|
70
|
+
if label_panels:
|
|
71
|
+
letter = chr(ord("A") + idx)
|
|
72
|
+
ax.text(-0.02, 1.02, letter, transform=ax.transAxes,
|
|
73
|
+
fontsize=14, fontweight="bold", va="bottom")
|
|
74
|
+
|
|
75
|
+
panel_fig.tight_layout(pad=0.4)
|
|
76
|
+
return panel_fig
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ── Dialog ───────────────────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class LayoutDialog(QDialog):
|
|
83
|
+
"""GUI for composing a multi-panel publication figure."""
|
|
84
|
+
|
|
85
|
+
def __init__(self, project, render_fn, parent=None):
|
|
86
|
+
super().__init__(parent)
|
|
87
|
+
self.setWindowTitle("Figure Layout")
|
|
88
|
+
self.setMinimumSize(520, 480)
|
|
89
|
+
self._project = project
|
|
90
|
+
self._render_fn = render_fn
|
|
91
|
+
self._panel_fig = None
|
|
92
|
+
|
|
93
|
+
layout = QVBoxLayout(self)
|
|
94
|
+
|
|
95
|
+
# ── Graph selector ────────────────────────────────────────────
|
|
96
|
+
grp_sel = QGroupBox("Select graphs to include (Ctrl/Shift to multi-select)")
|
|
97
|
+
v = QVBoxLayout(grp_sel)
|
|
98
|
+
self._graph_list = QListWidget()
|
|
99
|
+
self._graph_list.setSelectionMode(
|
|
100
|
+
QAbstractItemView.SelectionMode.ExtendedSelection
|
|
101
|
+
)
|
|
102
|
+
for gc in project.graphs:
|
|
103
|
+
self._graph_list.addItem(gc.name)
|
|
104
|
+
if self._graph_list.count():
|
|
105
|
+
self._graph_list.selectAll()
|
|
106
|
+
v.addWidget(self._graph_list)
|
|
107
|
+
layout.addWidget(grp_sel)
|
|
108
|
+
|
|
109
|
+
# ── Layout controls ───────────────────────────────────────────
|
|
110
|
+
grp_ctrl = QGroupBox("Panel layout")
|
|
111
|
+
form = QFormLayout(grp_ctrl)
|
|
112
|
+
|
|
113
|
+
self._rows_spin = QSpinBox()
|
|
114
|
+
self._rows_spin.setRange(1, 8)
|
|
115
|
+
self._rows_spin.setValue(1)
|
|
116
|
+
form.addRow("Rows:", self._rows_spin)
|
|
117
|
+
|
|
118
|
+
self._cols_spin = QSpinBox()
|
|
119
|
+
self._cols_spin.setRange(1, 8)
|
|
120
|
+
self._cols_spin.setValue(min(len(project.graphs), 3) or 1)
|
|
121
|
+
form.addRow("Columns:", self._cols_spin)
|
|
122
|
+
|
|
123
|
+
self._label_chk_cb = QComboBox()
|
|
124
|
+
self._label_chk_cb.addItems(["A, B, C … labels", "No panel labels"])
|
|
125
|
+
form.addRow("Panel labels:", self._label_chk_cb)
|
|
126
|
+
|
|
127
|
+
self._dpi_spin = QSpinBox()
|
|
128
|
+
self._dpi_spin.setRange(72, 600)
|
|
129
|
+
self._dpi_spin.setValue(150)
|
|
130
|
+
self._dpi_spin.setSuffix(" dpi")
|
|
131
|
+
form.addRow("Preview DPI:", self._dpi_spin)
|
|
132
|
+
|
|
133
|
+
layout.addWidget(grp_ctrl)
|
|
134
|
+
|
|
135
|
+
# ── Action buttons ────────────────────────────────────────────
|
|
136
|
+
btn_row = QHBoxLayout()
|
|
137
|
+
|
|
138
|
+
preview_btn = QPushButton("Preview Panel")
|
|
139
|
+
preview_btn.setDefault(True)
|
|
140
|
+
preview_btn.clicked.connect(self._preview)
|
|
141
|
+
btn_row.addWidget(preview_btn)
|
|
142
|
+
|
|
143
|
+
btn_row.addStretch()
|
|
144
|
+
|
|
145
|
+
export_btn = QPushButton("Export…")
|
|
146
|
+
export_btn.clicked.connect(self._export)
|
|
147
|
+
btn_row.addWidget(export_btn)
|
|
148
|
+
|
|
149
|
+
close_btn = QPushButton("Close")
|
|
150
|
+
close_btn.clicked.connect(self.reject)
|
|
151
|
+
btn_row.addWidget(close_btn)
|
|
152
|
+
|
|
153
|
+
layout.addLayout(btn_row)
|
|
154
|
+
|
|
155
|
+
self._status = QLabel("")
|
|
156
|
+
self._status.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
157
|
+
layout.addWidget(self._status)
|
|
158
|
+
|
|
159
|
+
# ------------------------------------------------------------------
|
|
160
|
+
def _selected_gcs(self):
|
|
161
|
+
names = {item.text() for item in self._graph_list.selectedItems()}
|
|
162
|
+
return [gc for gc in self._project.graphs if gc.name in names]
|
|
163
|
+
|
|
164
|
+
def _preview(self):
|
|
165
|
+
gcs = self._selected_gcs()
|
|
166
|
+
if not gcs:
|
|
167
|
+
self._status.setText("Select at least one graph.")
|
|
168
|
+
return
|
|
169
|
+
nrows = self._rows_spin.value()
|
|
170
|
+
ncols = self._cols_spin.value()
|
|
171
|
+
dpi = self._dpi_spin.value()
|
|
172
|
+
label = self._label_chk_cb.currentIndex() == 0
|
|
173
|
+
|
|
174
|
+
self._status.setText("Rendering…")
|
|
175
|
+
self.repaint()
|
|
176
|
+
try:
|
|
177
|
+
self._panel_fig = build_panel_figure(
|
|
178
|
+
gcs, self._render_fn, nrows, ncols,
|
|
179
|
+
dpi=dpi, label_panels=label,
|
|
180
|
+
)
|
|
181
|
+
# Show in a new matplotlib window
|
|
182
|
+
self._panel_fig.show()
|
|
183
|
+
self._status.setText(
|
|
184
|
+
f"Panel: {nrows} x {ncols} ({len(gcs)} graph(s)) — rendered OK"
|
|
185
|
+
)
|
|
186
|
+
except Exception as exc:
|
|
187
|
+
self._status.setText(f"Error: {exc}")
|
|
188
|
+
|
|
189
|
+
@styles.styled
|
|
190
|
+
def _export(self):
|
|
191
|
+
gcs = self._selected_gcs()
|
|
192
|
+
if not gcs:
|
|
193
|
+
self._status.setText("Select at least one graph.")
|
|
194
|
+
return
|
|
195
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
196
|
+
self, "Export Panel Figure", "panel_figure",
|
|
197
|
+
"PNG (*.png);;PDF (*.pdf);;SVG (*.svg);;TIFF (*.tiff)",
|
|
198
|
+
)
|
|
199
|
+
if not path:
|
|
200
|
+
return
|
|
201
|
+
|
|
202
|
+
nrows = self._rows_spin.value()
|
|
203
|
+
ncols = self._cols_spin.value()
|
|
204
|
+
label = self._label_chk_cb.currentIndex() == 0
|
|
205
|
+
export_dpi = 300 if path.lower().endswith((".tiff", ".tif")) else 200
|
|
206
|
+
|
|
207
|
+
self._status.setText("Exporting…")
|
|
208
|
+
self.repaint()
|
|
209
|
+
try:
|
|
210
|
+
fig = build_panel_figure(
|
|
211
|
+
gcs, self._render_fn, nrows, ncols,
|
|
212
|
+
dpi=export_dpi, label_panels=label,
|
|
213
|
+
)
|
|
214
|
+
fig.savefig(path, dpi=export_dpi, bbox_inches="tight")
|
|
215
|
+
import os
|
|
216
|
+
self._status.setText(f"Saved: {os.path.basename(path)}")
|
|
217
|
+
except Exception as exc:
|
|
218
|
+
self._status.setText(f"Export error: {exc}")
|