lessPython 0.2.0__py3-none-any.whl → 0.3.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 (48) hide show
  1. lessPy/ANOVA.py +5 -5
  2. lessPy/Chart.py +386 -88
  3. lessPy/Correlation.py +2 -2
  4. lessPy/Logit.py +2 -2
  5. lessPy/Regression.py +6 -4
  6. lessPy/X.py +279 -42
  7. lessPy/XY.py +814 -158
  8. lessPy/__init__.py +12 -2
  9. lessPy/_themes.py +5007 -0
  10. lessPy/bc_items_plotly.py +31 -18
  11. lessPy/bc_plotly.py +23 -7
  12. lessPy/bubble_plotly.py +17 -2
  13. lessPy/corCFA.py +3 -3
  14. lessPy/corProp.py +2 -2
  15. lessPy/corReflect.py +2 -2
  16. lessPy/corReorder.py +2 -2
  17. lessPy/corScree.py +3 -3
  18. lessPy/data/StockPrice.csv +1401 -1386
  19. lessPy/details.py +17 -4
  20. lessPy/dn_plotly.py +65 -45
  21. lessPy/freq_poly_plotly.py +12 -5
  22. lessPy/getColors.py +247 -20
  23. lessPy/hier_plotly.py +36 -9
  24. lessPy/hs_plotly.py +16 -4
  25. lessPy/plotly_utils.py +78 -9
  26. lessPy/plt_mat_plotly.py +74 -2
  27. lessPy/plt_time.py +10 -3
  28. lessPy/prob_norm.py +3 -3
  29. lessPy/prob_tcut.py +3 -3
  30. lessPy/prob_znorm.py +3 -1
  31. lessPy/rcolors.py +461 -0
  32. lessPy/simCImean.py +3 -3
  33. lessPy/simCLT.py +3 -3
  34. lessPy/simFlips.py +3 -3
  35. lessPy/simMeans.py +3 -3
  36. lessPy/stats_out.py +257 -11
  37. lessPy/style.py +160 -0
  38. lessPy/sunflower_plotly.py +140 -0
  39. lessPy/ttest.py +5 -5
  40. lessPy/utils.py +43 -6
  41. lessPy/vbs_plotly.py +16 -5
  42. lessPy/x_console.py +763 -0
  43. {lesspython-0.2.0.dist-info → lesspython-0.3.0.dist-info}/METADATA +6 -2
  44. lesspython-0.3.0.dist-info/RECORD +89 -0
  45. lesspython-0.2.0.dist-info/RECORD +0 -84
  46. {lesspython-0.2.0.dist-info → lesspython-0.3.0.dist-info}/WHEEL +0 -0
  47. {lesspython-0.2.0.dist-info → lesspython-0.3.0.dist-info}/licenses/LICENSE +0 -0
  48. {lesspython-0.2.0.dist-info → lesspython-0.3.0.dist-info}/top_level.txt +0 -0
lessPy/utils.py CHANGED
@@ -8,9 +8,9 @@ import math
8
8
 
9
9
  # style settings; R analog: options() set by lessR style()
10
10
  _OPTIONS = {
11
- "main_size": 1.0,
12
- "lab_size": 1.0,
13
- "axis_size": 0.9,
11
+ "main_size": 1.16, # zzz_on.R
12
+ "lab_size": 1.05, # zzz_on.R
13
+ "axis_size": 0.80, # zzz_on.R
14
14
  "axis_color": "black",
15
15
  "lab_color": "black",
16
16
  "grid_color": "gray90",
@@ -23,6 +23,7 @@ _OPTIONS = {
23
23
  "panel_fill": "white",
24
24
  "window_fill": "white",
25
25
  "digits_d": 2,
26
+ "suggest": True, # >>> Suggestions, as R
26
27
  "pt_color": "#324E5C", # rgb(50,78,92), zzz_on.R
27
28
  "trans_pt_fill": 0.10,
28
29
  "segment_color": "gray40",
@@ -159,9 +160,10 @@ def resolve_facet(data, facet, fun):
159
160
  "facet names a categorical variable for its "
160
161
  "panels")
161
162
  if len(facet) > 2:
162
- print(f"facet has {len(facet)} variables. {fun}() "
163
- "uses the first two: "
164
- f"{facet[0]}, {facet[1]}.")
163
+ from .stats_out import advise
164
+ advise(f"facet has {len(facet)} variables. {fun}() "
165
+ "uses the first two: "
166
+ f"{facet[0]}, {facet[1]}.")
165
167
  f1 = get_column(data, facet[0], "facet")
166
168
  if len(facet) == 1:
167
169
  return f1, facet[0], None, None
@@ -273,3 +275,38 @@ def pretty(lo, hi, n=5):
273
275
  vals = [(ns + i) * unit for i in range(int(nu - ns) + 1)]
274
276
  # avoid -0.0 and float dust such as 0.30000000000000004
275
277
  return [round(v, 10) + 0.0 for v in vals]
278
+
279
+
280
+ def _in_notebook():
281
+ """True in a notebook kernel (Jupyter, Colab, VS Code), False in
282
+ a script, the terminal, or the IPython console."""
283
+ try:
284
+ from IPython import get_ipython
285
+ except ImportError:
286
+ return False
287
+ ip = get_ipython()
288
+ return ip is not None and getattr(ip, "kernel", None) is not None
289
+
290
+
291
+ def show_plots(result):
292
+ """Show the figures an analysis returns, as lessR draws its
293
+ graphics as it runs. Only in a notebook: elsewhere fig.show()
294
+ opens a browser tab per figure, so the figures stay in .plots
295
+ (or .attrs["plots"] for a returned DataFrame). Displayed as a
296
+ notebook displays a returned Chart() figure; a display failure
297
+ leaves the figures in .plots rather than lose the analysis.
298
+ Returns result."""
299
+ attrs = getattr(result, "attrs", None)
300
+ plots = (attrs.get("plots") if isinstance(attrs, dict)
301
+ else getattr(result, "plots", None))
302
+ if plots and _in_notebook():
303
+ from IPython.display import display
304
+ try:
305
+ for fig in plots.values():
306
+ if fig is not None:
307
+ display(fig)
308
+ except Exception as e:
309
+ import warnings
310
+ warnings.warn(f"figures not displayed ({e}); they are "
311
+ "in .plots, show one with .show()")
312
+ return result
lessPy/vbs_plotly.py CHANGED
@@ -200,9 +200,10 @@ def vbs_plotly(x, x_name=None, vbs_plot="vbs",
200
200
  strip = "s" in vbs_plot
201
201
 
202
202
  # grouped replication measures, .param.VBS() group branch;
203
- # by and facet share the branch, as .param.VBS() does
204
- grp = by if by is not None else facet
205
- grp_ord = by_order if by is not None else facet_order
203
+ # by and facet share the branch, the facet levels when both are
204
+ # given (.param.VBS(): facet1 <- by0 only when facet1 is missing)
205
+ grp = facet if facet is not None else by
206
+ grp_ord = facet_order if facet is not None else by_order
206
207
  if grp is not None:
207
208
  mx_gc = max((grp == nm).sum() for nm in grp_ord)
208
209
  mc_w = max(int(np.unique(x[grp == nm],
@@ -210,7 +211,9 @@ def vbs_plotly(x, x_name=None, vbs_plot="vbs",
210
211
  for nm in grp_ord if (grp == nm).any())
211
212
  reps = (n - n_ux) / n > 0.15 and mc_w > 0.05 * n
212
213
 
213
- # jitter_x breaks ties in the data itself, as in X.R
214
+ # jitter_x breaks ties in the data itself, as in X.R; the violin
215
+ # bandwidth is read from the data as given, as .param.VBS() does
216
+ x_given = x.copy()
214
217
  if jitter_x is None:
215
218
  if grp is None:
216
219
  jitter_x = 1.1 * (1 - np.exp(-0.03 * mx_c))
@@ -263,6 +266,14 @@ def vbs_plotly(x, x_name=None, vbs_plot="vbs",
263
266
  vpart = f"%{{x:{val_fmt}}}" if val_fmt else "%{x}"
264
267
  rng_ = np.random.default_rng(n) # reproducible spread
265
268
  jy = 0.5 if jitter_y is None else float(jitter_y)
269
+ # the values plotted, for X()'s "Parameter values" report; one
270
+ # bandwidth only when one violin is drawn (facets take their own)
271
+ from .stats_out import record_stats
272
+ record_stats(pt_size=float(cex), out_size=float(out_cex),
273
+ jitter_x=float(jitter_x), jitter_y=jy,
274
+ bw=(float(bw) if bw is not None else
275
+ float(band_width(x_given, bw_iter)) if facet is None
276
+ else None))
266
277
 
267
278
  # facet units, first level in the TOP band (reading order, as
268
279
  # lessR as.table=TRUE); facet2 stacks one section of facet
@@ -326,7 +337,7 @@ def vbs_plotly(x, x_name=None, vbs_plot="vbs",
326
337
  # violin: mirrored KDE, max width = vbs_ratio
327
338
  if violin and len(xu) > 1:
328
339
  h = (bw if bw is not None
329
- else band_width(xu, bw_iter))
340
+ else band_width(x_given[um], bw_iter))
330
341
  grid = np.linspace(xu.min() - 3 * h,
331
342
  xu.max() + 3 * h, 512)
332
343
  dens = kde(xu, grid, h)