scitex 2.3.0__py3-none-any.whl → 2.4.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.
- scitex/ai/classification/reporters/reporter_utils/_Plotter.py +1 -1
- scitex/ai/plt/__init__.py +2 -2
- scitex/ai/plt/{_plot_conf_mat.py → _stx_conf_mat.py} +3 -3
- scitex/config/PriorityConfig.py +195 -0
- scitex/config/__init__.py +24 -0
- scitex/io/_save.py +125 -34
- scitex/io/_save_modules/_image.py +37 -20
- scitex/plt/__init__.py +470 -17
- scitex/plt/_subplots/_AxisWrapper.py +98 -50
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin.py +254 -124
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin.py +49 -8
- scitex/plt/_subplots/_SubplotsWrapper.py +76 -91
- scitex/plt/_subplots/_export_as_csv.py +127 -58
- scitex/plt/_subplots/_export_as_csv_formatters/__init__.py +25 -16
- scitex/plt/_subplots/_export_as_csv_formatters/_format_contourf.py +54 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hexbin.py +41 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hist2d.py +41 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_imshow.py +59 -47
- scitex/plt/_subplots/_export_as_csv_formatters/_format_matshow.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_pie.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot.py +72 -35
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_box.py +1 -1
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_kde.py +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/_format_quiver.py +53 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stem.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_step.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_streamplot.py +48 -0
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_conf_mat.py → _format_stx_conf_mat.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_ecdf.py → _format_stx_ecdf.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_fillv.py → _format_stx_fillv.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_heatmap.py → _format_stx_heatmap.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_image.py → _format_stx_image.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_joyplot.py → _format_stx_joyplot.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_line.py → _format_stx_line.py} +3 -3
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_mean_ci.py → _format_stx_mean_ci.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_mean_std.py → _format_stx_mean_std.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_median_iqr.py → _format_stx_median_iqr.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_raster.py → _format_stx_raster.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_rectangle.py → _format_stx_rectangle.py} +1 -1
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_scatter_hist.py → _format_stx_scatter_hist.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_shaded_line.py → _format_stx_shaded_line.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_violin.py → _format_stx_violin.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/verify_formatters.py +23 -23
- scitex/plt/ax/__init__.py +16 -15
- scitex/plt/ax/_plot/__init__.py +30 -30
- scitex/plt/ax/_plot/_add_fitted_line.py +65 -11
- scitex/plt/ax/_plot/_plot_statistical_shaded_line.py +104 -76
- scitex/plt/ax/_plot/{_plot_conf_mat.py → _stx_conf_mat.py} +10 -10
- scitex/plt/ax/_plot/_stx_ecdf.py +109 -0
- scitex/plt/ax/_plot/{_plot_fillv.py → _stx_fillv.py} +7 -7
- scitex/plt/ax/_plot/_stx_heatmap.py +366 -0
- scitex/plt/ax/_plot/{_plot_image.py → _stx_image.py} +1 -1
- scitex/plt/ax/_plot/_stx_joyplot.py +113 -0
- scitex/plt/ax/_plot/{_plot_raster.py → _stx_raster.py} +37 -25
- scitex/plt/ax/_plot/{_plot_rectangle.py → _stx_rectangle.py} +10 -9
- scitex/plt/ax/_plot/{_plot_scatter_hist.py → _stx_scatter_hist.py} +1 -1
- scitex/plt/ax/_plot/_stx_shaded_line.py +215 -0
- scitex/plt/ax/_plot/{_plot_violin.py → _stx_violin.py} +13 -6
- scitex/plt/ax/_style/__init__.py +3 -0
- scitex/plt/ax/_style/_style_barplot.py +13 -2
- scitex/plt/ax/_style/_style_boxplot.py +78 -32
- scitex/plt/ax/_style/_style_errorbar.py +17 -3
- scitex/plt/ax/_style/_style_scatter.py +17 -3
- scitex/plt/ax/_style/_style_violinplot.py +109 -0
- scitex/plt/color/_vizualize_colors.py +3 -3
- scitex/plt/styles/SCITEX_STYLE.yaml +104 -0
- scitex/plt/styles/__init__.py +57 -0
- scitex/plt/styles/_plot_defaults.py +209 -0
- scitex/plt/styles/_plot_postprocess.py +518 -0
- scitex/plt/styles/_style_loader.py +268 -0
- scitex/plt/styles/presets.py +208 -0
- scitex/plt/utils/_collect_figure_metadata.py +160 -18
- scitex/plt/utils/_colorbar.py +72 -10
- scitex/plt/utils/_configure_mpl.py +108 -52
- scitex/plt/utils/_crop.py +21 -7
- scitex/plt/utils/_figure_mm.py +21 -7
- scitex/stats/__init__.py +13 -1
- scitex/stats/_schema.py +578 -0
- scitex/stats/tests/__init__.py +13 -0
- scitex/stats/tests/correlation/__init__.py +13 -0
- scitex/stats/tests/correlation/_test_pearson.py +262 -0
- scitex/vis/__init__.py +6 -0
- scitex/vis/editor/__init__.py +23 -0
- scitex/vis/editor/_defaults.py +205 -0
- scitex/vis/editor/_edit.py +342 -0
- scitex/vis/editor/_mpl_editor.py +231 -0
- scitex/vis/editor/_tkinter_editor.py +466 -0
- scitex/vis/editor/_web_editor.py +1440 -0
- scitex/vis/model/plot_types.py +15 -15
- {scitex-2.3.0.dist-info → scitex-2.4.0.dist-info}/METADATA +2 -1
- {scitex-2.3.0.dist-info → scitex-2.4.0.dist-info}/RECORD +94 -67
- {scitex-2.3.0.dist-info → scitex-2.4.0.dist-info}/WHEEL +1 -1
- scitex/plt/ax/_plot/_plot_ecdf.py +0 -84
- scitex/plt/ax/_plot/_plot_heatmap.py +0 -277
- scitex/plt/ax/_plot/_plot_joyplot.py +0 -77
- scitex/plt/ax/_plot/_plot_shaded_line.py +0 -142
- scitex/plt/presets.py +0 -224
- {scitex-2.3.0.dist-info → scitex-2.4.0.dist-info}/entry_points.txt +0 -0
- {scitex-2.3.0.dist-info → scitex-2.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -38,7 +38,7 @@ def test_all_formatters():
|
|
|
38
38
|
|
|
39
39
|
def test_plot_kde():
|
|
40
40
|
"""Test KDE plotting and CSV export."""
|
|
41
|
-
print("Testing
|
|
41
|
+
print("Testing stx_kde...")
|
|
42
42
|
|
|
43
43
|
# Create figure
|
|
44
44
|
fig, ax = scitex.plt.subplots()
|
|
@@ -48,7 +48,7 @@ def test_plot_kde():
|
|
|
48
48
|
data = np.concatenate([np.random.normal(0, 1, 500), np.random.normal(5, 1, 300)])
|
|
49
49
|
|
|
50
50
|
# Plot with ID for tracking
|
|
51
|
-
ax.
|
|
51
|
+
ax.stx_kde(data, label="Bimodal Distribution", id="kde_test")
|
|
52
52
|
|
|
53
53
|
# Style the plot
|
|
54
54
|
ax.set_xyt("Value", "Density", "KDE Test")
|
|
@@ -69,11 +69,11 @@ def test_plot_kde():
|
|
|
69
69
|
|
|
70
70
|
# Close figure
|
|
71
71
|
scitex.plt.close(fig)
|
|
72
|
-
print("✓
|
|
72
|
+
print("✓ stx_kde test successful")
|
|
73
73
|
|
|
74
74
|
def test_plot_image():
|
|
75
75
|
"""Test image plotting and CSV export."""
|
|
76
|
-
print("Testing
|
|
76
|
+
print("Testing stx_image...")
|
|
77
77
|
|
|
78
78
|
# Create figure
|
|
79
79
|
fig, ax = scitex.plt.subplots()
|
|
@@ -83,7 +83,7 @@ def test_plot_image():
|
|
|
83
83
|
data = np.random.rand(20, 20)
|
|
84
84
|
|
|
85
85
|
# Plot with ID for tracking
|
|
86
|
-
ax.
|
|
86
|
+
ax.stx_image(data, cmap="viridis", id="image_test")
|
|
87
87
|
|
|
88
88
|
# Style the plot
|
|
89
89
|
ax.set_xyt("X", "Y", "Image Test")
|
|
@@ -103,11 +103,11 @@ def test_plot_image():
|
|
|
103
103
|
|
|
104
104
|
# Close figure
|
|
105
105
|
scitex.plt.close(fig)
|
|
106
|
-
print("✓
|
|
106
|
+
print("✓ stx_image test successful")
|
|
107
107
|
|
|
108
108
|
def test_plot_shaded_line():
|
|
109
109
|
"""Test shaded line plotting and CSV export."""
|
|
110
|
-
print("Testing
|
|
110
|
+
print("Testing stx_shaded_line...")
|
|
111
111
|
|
|
112
112
|
# Create figure
|
|
113
113
|
fig, ax = scitex.plt.subplots()
|
|
@@ -120,7 +120,7 @@ def test_plot_shaded_line():
|
|
|
120
120
|
y_upper = y_middle + 0.2
|
|
121
121
|
|
|
122
122
|
# Plot with ID for tracking
|
|
123
|
-
ax.
|
|
123
|
+
ax.stx_shaded_line(x, y_lower, y_middle, y_upper, label="Sine with error", id="shaded_line_test")
|
|
124
124
|
|
|
125
125
|
# Style the plot
|
|
126
126
|
ax.set_xyt("X", "Y", "Shaded Line Test")
|
|
@@ -140,11 +140,11 @@ def test_plot_shaded_line():
|
|
|
140
140
|
|
|
141
141
|
# Close figure
|
|
142
142
|
scitex.plt.close(fig)
|
|
143
|
-
print("✓
|
|
143
|
+
print("✓ stx_shaded_line test successful")
|
|
144
144
|
|
|
145
145
|
def test_plot_scatter_hist():
|
|
146
146
|
"""Test scatter histogram plotting and CSV export."""
|
|
147
|
-
print("Testing
|
|
147
|
+
print("Testing stx_scatter_hist...")
|
|
148
148
|
|
|
149
149
|
# Create figure
|
|
150
150
|
fig, ax = scitex.plt.subplots(figsize=(8, 8))
|
|
@@ -155,7 +155,7 @@ def test_plot_scatter_hist():
|
|
|
155
155
|
y = x + np.random.normal(0, 0.5, 500)
|
|
156
156
|
|
|
157
157
|
# Plot with ID for tracking
|
|
158
|
-
ax.
|
|
158
|
+
ax.stx_scatter_hist(x, y, hist_bins=30, scatter_alpha=0.7, id="scatter_hist_test")
|
|
159
159
|
|
|
160
160
|
# Style the plot
|
|
161
161
|
ax.set_xyt("X Values", "Y Values", "Scatter Histogram Test")
|
|
@@ -174,11 +174,11 @@ def test_plot_scatter_hist():
|
|
|
174
174
|
|
|
175
175
|
# Close figure
|
|
176
176
|
scitex.plt.close(fig)
|
|
177
|
-
print("✓
|
|
177
|
+
print("✓ stx_scatter_hist test successful")
|
|
178
178
|
|
|
179
179
|
def test_plot_violin():
|
|
180
180
|
"""Test violin plotting and CSV export."""
|
|
181
|
-
print("Testing
|
|
181
|
+
print("Testing stx_violin...")
|
|
182
182
|
|
|
183
183
|
# Create figure
|
|
184
184
|
fig, ax = scitex.plt.subplots()
|
|
@@ -193,7 +193,7 @@ def test_plot_violin():
|
|
|
193
193
|
labels = ["Group A", "Group B", "Group C"]
|
|
194
194
|
|
|
195
195
|
# Plot with ID for tracking
|
|
196
|
-
ax.
|
|
196
|
+
ax.stx_violin(data, labels=labels, colors=["red", "blue", "green"], id="violin_test")
|
|
197
197
|
|
|
198
198
|
# Style the plot
|
|
199
199
|
ax.set_xyt("Groups", "Values", "Violin Plot Test")
|
|
@@ -212,11 +212,11 @@ def test_plot_violin():
|
|
|
212
212
|
|
|
213
213
|
# Close figure
|
|
214
214
|
scitex.plt.close(fig)
|
|
215
|
-
print("✓
|
|
215
|
+
print("✓ stx_violin test successful")
|
|
216
216
|
|
|
217
217
|
def test_plot_heatmap():
|
|
218
218
|
"""Test heatmap plotting and CSV export."""
|
|
219
|
-
print("Testing
|
|
219
|
+
print("Testing stx_heatmap...")
|
|
220
220
|
|
|
221
221
|
# Create figure
|
|
222
222
|
fig, ax = scitex.plt.subplots()
|
|
@@ -228,7 +228,7 @@ def test_plot_heatmap():
|
|
|
228
228
|
y_labels = [f"Y{ii+1}" for ii in range(10)]
|
|
229
229
|
|
|
230
230
|
# Plot with ID for tracking
|
|
231
|
-
ax.
|
|
231
|
+
ax.stx_heatmap(
|
|
232
232
|
data,
|
|
233
233
|
x_labels=x_labels,
|
|
234
234
|
y_labels=y_labels,
|
|
@@ -256,11 +256,11 @@ def test_plot_heatmap():
|
|
|
256
256
|
|
|
257
257
|
# Close figure
|
|
258
258
|
scitex.plt.close(fig)
|
|
259
|
-
print("✓
|
|
259
|
+
print("✓ stx_heatmap test successful")
|
|
260
260
|
|
|
261
261
|
def test_plot_ecdf():
|
|
262
262
|
"""Test ECDF plotting and CSV export."""
|
|
263
|
-
print("Testing
|
|
263
|
+
print("Testing stx_ecdf...")
|
|
264
264
|
|
|
265
265
|
# Create figure
|
|
266
266
|
fig, ax = scitex.plt.subplots()
|
|
@@ -270,7 +270,7 @@ def test_plot_ecdf():
|
|
|
270
270
|
data = np.random.normal(0, 1, 1000)
|
|
271
271
|
|
|
272
272
|
# Plot with ID for tracking
|
|
273
|
-
ax.
|
|
273
|
+
ax.stx_ecdf(data, label="Normal Distribution", id="ecdf_test")
|
|
274
274
|
|
|
275
275
|
# Style the plot
|
|
276
276
|
ax.set_xyt("Value", "Cumulative Probability", "ECDF Test")
|
|
@@ -290,7 +290,7 @@ def test_plot_ecdf():
|
|
|
290
290
|
|
|
291
291
|
# Close figure
|
|
292
292
|
scitex.plt.close(fig)
|
|
293
|
-
print("✓
|
|
293
|
+
print("✓ stx_ecdf test successful")
|
|
294
294
|
|
|
295
295
|
def test_multiple_plots():
|
|
296
296
|
"""Test multiple plots on the same axis."""
|
|
@@ -306,8 +306,8 @@ def test_multiple_plots():
|
|
|
306
306
|
y2 = np.cos(x)
|
|
307
307
|
|
|
308
308
|
# Create multiple plots with different IDs
|
|
309
|
-
ax.
|
|
310
|
-
ax.
|
|
309
|
+
ax.stx_line(y1, label="Sine", id="multi_test_sine")
|
|
310
|
+
ax.stx_line(y2, label="Cosine", id="multi_test_cosine")
|
|
311
311
|
|
|
312
312
|
# Style the plot
|
|
313
313
|
ax.set_xyt("X", "Y", "Multiple Plots Test")
|
scitex/plt/ax/__init__.py
CHANGED
|
@@ -55,26 +55,27 @@ from ._style._style_errorbar import style_errorbar
|
|
|
55
55
|
from ._style._style_barplot import style_barplot
|
|
56
56
|
from ._style._style_scatter import style_scatter
|
|
57
57
|
from ._style._style_suptitles import style_suptitles
|
|
58
|
+
from ._style._style_violinplot import style_violinplot
|
|
58
59
|
|
|
59
60
|
# Plot
|
|
60
|
-
from ._plot.
|
|
61
|
+
from ._plot._stx_heatmap import stx_heatmap
|
|
61
62
|
from ._plot._plot_circular_hist import plot_circular_hist
|
|
62
|
-
from ._plot.
|
|
63
|
+
from ._plot._stx_conf_mat import stx_conf_mat
|
|
63
64
|
from ._plot._plot_cube import plot_cube
|
|
64
|
-
from ._plot.
|
|
65
|
-
from ._plot.
|
|
66
|
-
from ._plot.
|
|
67
|
-
from ._plot.
|
|
68
|
-
from ._plot.
|
|
69
|
-
from ._plot.
|
|
70
|
-
from ._plot.
|
|
71
|
-
from ._plot.
|
|
72
|
-
from ._plot.
|
|
65
|
+
from ._plot._stx_ecdf import stx_ecdf
|
|
66
|
+
from ._plot._stx_fillv import stx_fillv
|
|
67
|
+
from ._plot._stx_violin import stx_violin
|
|
68
|
+
from ._plot._stx_image import stx_image
|
|
69
|
+
from ._plot._stx_joyplot import stx_joyplot
|
|
70
|
+
from ._plot._stx_raster import stx_raster
|
|
71
|
+
from ._plot._stx_rectangle import stx_rectangle
|
|
72
|
+
from ._plot._stx_scatter_hist import stx_scatter_hist
|
|
73
|
+
from ._plot._stx_shaded_line import stx_shaded_line
|
|
73
74
|
from ._plot._plot_statistical_shaded_line import (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
stx_line,
|
|
76
|
+
stx_mean_std,
|
|
77
|
+
stx_mean_ci,
|
|
78
|
+
stx_median_iqr,
|
|
78
79
|
)
|
|
79
80
|
from ._plot._add_fitted_line import add_fitted_line
|
|
80
81
|
|
scitex/plt/ax/_plot/__init__.py
CHANGED
|
@@ -8,47 +8,47 @@ import os
|
|
|
8
8
|
__FILE__ = "./src/scitex/plt/ax/_plot/__init__.py"
|
|
9
9
|
__DIR__ = os.path.dirname(__FILE__)
|
|
10
10
|
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
11
|
+
from ._stx_scatter_hist import stx_scatter_hist
|
|
12
|
+
from ._stx_heatmap import stx_heatmap
|
|
13
13
|
from ._plot_circular_hist import plot_circular_hist
|
|
14
|
-
from .
|
|
14
|
+
from ._stx_conf_mat import stx_conf_mat
|
|
15
15
|
from ._plot_cube import plot_cube
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
18
|
-
from .
|
|
19
|
-
from .
|
|
20
|
-
from .
|
|
21
|
-
from .
|
|
22
|
-
from .
|
|
23
|
-
from .
|
|
16
|
+
from ._stx_ecdf import stx_ecdf
|
|
17
|
+
from ._stx_fillv import stx_fillv
|
|
18
|
+
from ._stx_violin import stx_violin, sns_plot_violin
|
|
19
|
+
from ._stx_image import stx_image
|
|
20
|
+
from ._stx_joyplot import stx_joyplot
|
|
21
|
+
from ._stx_raster import stx_raster
|
|
22
|
+
from ._stx_rectangle import stx_rectangle
|
|
23
|
+
from ._stx_shaded_line import stx_shaded_line, _plot_single_shaded_line
|
|
24
24
|
from ._plot_statistical_shaded_line import (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
stx_line,
|
|
26
|
+
stx_mean_std,
|
|
27
|
+
stx_mean_ci,
|
|
28
|
+
stx_median_iqr,
|
|
29
29
|
)
|
|
30
30
|
from ._add_fitted_line import add_fitted_line
|
|
31
31
|
|
|
32
32
|
__all__ = [
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"stx_scatter_hist",
|
|
34
|
+
"stx_heatmap",
|
|
35
35
|
"plot_circular_hist",
|
|
36
|
-
"
|
|
36
|
+
"stx_conf_mat",
|
|
37
37
|
"plot_cube",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
38
|
+
"stx_ecdf",
|
|
39
|
+
"stx_fillv",
|
|
40
|
+
"stx_violin",
|
|
41
41
|
"sns_plot_violin",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
42
|
+
"stx_image",
|
|
43
|
+
"stx_joyplot",
|
|
44
|
+
"stx_raster",
|
|
45
|
+
"stx_rectangle",
|
|
46
|
+
"stx_shaded_line",
|
|
47
47
|
"_plot_single_shaded_line",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
48
|
+
"stx_line",
|
|
49
|
+
"stx_mean_std",
|
|
50
|
+
"stx_mean_ci",
|
|
51
|
+
"stx_median_iqr",
|
|
52
52
|
"add_fitted_line",
|
|
53
53
|
]
|
|
54
54
|
|
|
@@ -8,7 +8,7 @@ Add fitted regression line to scatter plots.
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import numpy as np
|
|
11
|
-
from typing import Optional, Tuple
|
|
11
|
+
from typing import Optional, Tuple, Dict
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def add_fitted_line(
|
|
@@ -20,9 +20,12 @@ def add_fitted_line(
|
|
|
20
20
|
linewidth_mm: float = 0.2,
|
|
21
21
|
label: Optional[str] = None,
|
|
22
22
|
degree: int = 1,
|
|
23
|
+
show_stats: bool = True,
|
|
24
|
+
stats_position: float = 0.75,
|
|
25
|
+
stats_fontsize: int = 6,
|
|
23
26
|
) -> Tuple:
|
|
24
27
|
"""
|
|
25
|
-
Add a fitted polynomial line to a scatter plot.
|
|
28
|
+
Add a fitted polynomial line to a scatter plot with optional R² and p-value.
|
|
26
29
|
|
|
27
30
|
Parameters
|
|
28
31
|
----------
|
|
@@ -42,6 +45,13 @@ def add_fitted_line(
|
|
|
42
45
|
Label for the fitted line (default: None)
|
|
43
46
|
degree : int, optional
|
|
44
47
|
Polynomial degree for fitting (default: 1 for linear)
|
|
48
|
+
show_stats : bool, optional
|
|
49
|
+
Whether to display R² and p-value near the line (default: True)
|
|
50
|
+
Only applicable for linear fits (degree=1)
|
|
51
|
+
stats_position : float, optional
|
|
52
|
+
Position along x-axis (0-1 scale) for stats text (default: 0.75)
|
|
53
|
+
stats_fontsize : int, optional
|
|
54
|
+
Font size for statistics text in points (default: 6)
|
|
45
55
|
|
|
46
56
|
Returns
|
|
47
57
|
-------
|
|
@@ -49,19 +59,24 @@ def add_fitted_line(
|
|
|
49
59
|
The fitted line object
|
|
50
60
|
coeffs : np.ndarray
|
|
51
61
|
Polynomial coefficients from np.polyfit
|
|
62
|
+
stats : StatResult or None
|
|
63
|
+
StatResult instance with correlation statistics (only for degree=1).
|
|
64
|
+
Use .to_dict() for dictionary format.
|
|
52
65
|
|
|
53
66
|
Examples
|
|
54
67
|
--------
|
|
55
68
|
>>> fig, ax = stx.plt.subplots(**stx.plt.presets.SCITEX_STYLE)
|
|
56
69
|
>>> scatter = ax.scatter(x, y)
|
|
57
|
-
>>> stx.plt.ax.add_fitted_line(ax, x, y)
|
|
58
|
-
|
|
59
|
-
>>> #
|
|
60
|
-
>>> line, coeffs = stx.plt.ax.add_fitted_line(
|
|
61
|
-
... ax, x, y,
|
|
62
|
-
...
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
>>> stx.plt.ax.add_fitted_line(ax, x, y) # Auto-shows R² and p
|
|
71
|
+
|
|
72
|
+
>>> # Without statistics
|
|
73
|
+
>>> line, coeffs, stats = stx.plt.ax.add_fitted_line(
|
|
74
|
+
... ax, x, y, show_stats=False
|
|
75
|
+
... )
|
|
76
|
+
|
|
77
|
+
>>> # Custom position for stats
|
|
78
|
+
>>> line, coeffs, stats = stx.plt.ax.add_fitted_line(
|
|
79
|
+
... ax, x, y, stats_position=0.5
|
|
65
80
|
... )
|
|
66
81
|
"""
|
|
67
82
|
from scitex.plt.utils import mm_to_pt
|
|
@@ -91,7 +106,46 @@ def add_fitted_line(
|
|
|
91
106
|
label=label,
|
|
92
107
|
)[0]
|
|
93
108
|
|
|
94
|
-
|
|
109
|
+
# Calculate and display statistics for linear regression (degree=1)
|
|
110
|
+
stats_result = None
|
|
111
|
+
if degree == 1 and show_stats:
|
|
112
|
+
# Import scitex.stats correlation test
|
|
113
|
+
from scitex.stats.tests.correlation import test_pearson
|
|
114
|
+
|
|
115
|
+
# Calculate correlation statistics using scitex.stats
|
|
116
|
+
stats_result = test_pearson(x, y)
|
|
117
|
+
|
|
118
|
+
# Position for text annotation
|
|
119
|
+
x_pos = x.min() + stats_position * (x.max() - x.min())
|
|
120
|
+
y_pos = poly_fn(x_pos)
|
|
121
|
+
|
|
122
|
+
# Format statistics text with R² and significance stars
|
|
123
|
+
r_squared = stats_result.effect_size['value'] # r_squared from effect_size
|
|
124
|
+
stars = stats_result.stars
|
|
125
|
+
|
|
126
|
+
if stars and stars != 'ns': # Only show if significant
|
|
127
|
+
stats_text = f"$R^2$ = {r_squared:.3f}{stars}"
|
|
128
|
+
else: # Not significant
|
|
129
|
+
stats_text = f"$R^2$ = {r_squared:.3f} (ns)"
|
|
130
|
+
|
|
131
|
+
# Add text annotation near the line
|
|
132
|
+
ax.text(
|
|
133
|
+
x_pos, y_pos,
|
|
134
|
+
stats_text,
|
|
135
|
+
verticalalignment='bottom',
|
|
136
|
+
fontsize=stats_fontsize
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Store stats in axes metadata for embedding in saved figures
|
|
140
|
+
if not hasattr(ax, '_scitex_metadata'):
|
|
141
|
+
ax._scitex_metadata = {}
|
|
142
|
+
if 'stats' not in ax._scitex_metadata:
|
|
143
|
+
ax._scitex_metadata['stats'] = []
|
|
144
|
+
|
|
145
|
+
# Add this StatResult to the stats list
|
|
146
|
+
ax._scitex_metadata['stats'].append(stats_result.to_dict())
|
|
147
|
+
|
|
148
|
+
return line, coeffs, stats_result
|
|
95
149
|
|
|
96
150
|
|
|
97
151
|
# EOF
|