lessPython 0.2.0__py3-none-any.whl → 0.3.1__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 (59) hide show
  1. lessPy/ANOVA.py +74 -15
  2. lessPy/Chart.py +431 -88
  3. lessPy/Correlation.py +40 -11
  4. lessPy/Flows.py +3 -3
  5. lessPy/Logit.py +15 -11
  6. lessPy/Regression.py +27 -21
  7. lessPy/X.py +280 -42
  8. lessPy/XY.py +1332 -239
  9. lessPy/__init__.py +12 -2
  10. lessPy/_themes.py +5007 -0
  11. lessPy/bc_items_plotly.py +33 -20
  12. lessPy/bc_plotly.py +27 -10
  13. lessPy/bubble_plotly.py +33 -17
  14. lessPy/corCFA.py +9 -5
  15. lessPy/corProp.py +8 -4
  16. lessPy/corReflect.py +8 -4
  17. lessPy/corReorder.py +8 -4
  18. lessPy/corScree.py +12 -8
  19. lessPy/data/StockPrice.csv +1401 -1386
  20. lessPy/details.py +17 -4
  21. lessPy/dn_plotly.py +74 -54
  22. lessPy/dot_plotly.py +9 -8
  23. lessPy/freq_poly_plotly.py +18 -11
  24. lessPy/getColors.py +247 -20
  25. lessPy/hier_plotly.py +41 -14
  26. lessPy/hs_plotly.py +23 -11
  27. lessPy/pie_plotly.py +1 -1
  28. lessPy/pivot.py +39 -9
  29. lessPy/plotly_utils.py +162 -29
  30. lessPy/plt_add.py +2 -7
  31. lessPy/plt_contour.py +6 -6
  32. lessPy/plt_contour_facet.py +3 -3
  33. lessPy/plt_mat_plotly.py +85 -12
  34. lessPy/plt_plotly.py +34 -18
  35. lessPy/plt_smooth.py +4 -4
  36. lessPy/plt_time.py +10 -3
  37. lessPy/prob_norm.py +7 -3
  38. lessPy/prob_tcut.py +7 -3
  39. lessPy/prob_znorm.py +7 -1
  40. lessPy/profile_plotly.py +5 -4
  41. lessPy/radar_plotly.py +4 -3
  42. lessPy/rcolors.py +461 -0
  43. lessPy/simCImean.py +7 -3
  44. lessPy/simCLT.py +7 -3
  45. lessPy/simFlips.py +7 -3
  46. lessPy/simMeans.py +7 -3
  47. lessPy/stats_out.py +257 -11
  48. lessPy/style.py +167 -0
  49. lessPy/sunflower_plotly.py +141 -0
  50. lessPy/ttest.py +17 -13
  51. lessPy/utils.py +146 -6
  52. lessPy/vbs_plotly.py +39 -27
  53. lessPy/x_console.py +763 -0
  54. {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/METADATA +13 -2
  55. lesspython-0.3.1.dist-info/RECORD +89 -0
  56. {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/WHEEL +1 -1
  57. lesspython-0.2.0.dist-info/RECORD +0 -84
  58. {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/licenses/LICENSE +0 -0
  59. {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/top_level.txt +0 -0
lessPy/ANOVA.py CHANGED
@@ -22,10 +22,10 @@ import pandas as pd
22
22
  import plotly.graph_objects as go
23
23
 
24
24
  from .plotly_utils import (
25
- BASE_COLORS, axis_cat, axis_format, axis_num, make_trans,
25
+ as_plotly_color, BASE_COLORS, axis_cat, axis_format, axis_num, make_trans,
26
26
  plot_border, plotly_style, to_hex, x_grid)
27
27
  from .Regression import _getdigits, _prntbl
28
- from .utils import fmt, get_column, get_option, pretty
28
+ from .utils import fmt, get_column, get_option, pretty, file_output, show_plots
29
29
 
30
30
 
31
31
  class ANOVAResults:
@@ -380,18 +380,73 @@ def _oneway(fit, yv, gv, y_name, x_name, levels, n_keep, d,
380
380
  lines += _prntbl(tukey, d).split("\n")
381
381
 
382
382
  plots = {}
383
+ if graphics and tukey is not None:
384
+ plots["tukey"] = _tukey_plot(tukey, x_name, d)
383
385
  if graphics:
384
386
  plots["means"] = _anova_means_plot(
385
387
  yv, gv, y_name, x_name, levels, jitter_x, d)
386
388
 
387
- return ANOVAResults(
389
+ return show_plots(ANOVAResults(
388
390
  formula=formula, design="oneway", n_obs=n_obs,
389
391
  n_keep=n_keep, digits_d=d, response=y_name,
390
392
  factors=[x_name], descriptive=desc, grand_mean=grand,
391
393
  anova=tbl,
392
394
  effects={"R_squared": rsq, "R_sq_adjusted": rsq_adj,
393
395
  "omega_squared": omsq, "cohen_f": cohen_f},
394
- tukey=tukey, plots=plots)
396
+ tukey=tukey, plots=plots))
397
+
398
+
399
+ def _tukey_plot(tukey, x_name, d):
400
+ """Each pairwise difference of means with its 95% family-wise
401
+ interval, the first comparison at the top, and a dashed
402
+ reference line at 0. ~ .ANOVAz1 plot(TukeyHSD())"""
403
+ style = plotly_style()
404
+ k = len(tukey)
405
+ ypos = list(range(k, 0, -1))
406
+ col = as_plotly_color(get_option("pt_color", "#324E5C"))
407
+ fig = go.Figure()
408
+ for yp, (lbl, r) in zip(ypos, tukey.iterrows()):
409
+ fig.add_trace(go.Scatter(
410
+ x=[r["lwr"], r["upr"]], y=[yp, yp], mode="lines",
411
+ line=dict(color=col, width=2), hoverinfo="skip",
412
+ showlegend=False))
413
+ fig.add_trace(go.Scatter(
414
+ x=tukey["diff"], y=ypos, mode="markers",
415
+ marker=dict(symbol="circle", size=9, color=col),
416
+ customdata=np.column_stack([tukey["lwr"], tukey["upr"],
417
+ tukey["p adj"]]),
418
+ text=list(tukey.index),
419
+ hovertemplate=("%{text}<br>diff: %{x:." + str(d) + "f}"
420
+ "<br>95% CI: %{customdata[0]:." + str(d)
421
+ + "f} to %{customdata[1]:." + str(d) + "f}"
422
+ "<br>p adj: %{customdata[2]:.3f}"
423
+ "<extra></extra>"),
424
+ showlegend=False))
425
+ axT1 = pretty(min(0.0, float(tukey["lwr"].min())),
426
+ max(0.0, float(tukey["upr"].max())))
427
+ ax_x = axis_num(f"Differences in mean levels of {x_name}", axT1,
428
+ axis_format(axT1, d))
429
+ ax_x.update(showgrid=True,
430
+ gridcolor=as_plotly_color(style["grid_col"]),
431
+ gridwidth=1, griddash="dot",
432
+ range=[axT1[0], axT1[-1]], zeroline=False)
433
+ ax_y = axis_cat("")
434
+ ax_y.update(tickmode="array", tickvals=ypos,
435
+ ticktext=list(tukey.index), range=[0.5, k + 0.5])
436
+ zero = dict(type="line", xref="x", yref="paper", x0=0, x1=0,
437
+ y0=0, y1=1, layer="below",
438
+ line=dict(color=as_plotly_color("gray50"), width=1,
439
+ dash="dash"))
440
+ fig.update_layout(
441
+ xaxis=ax_x, yaxis=ax_y, shapes=[zero] + list(plot_border()),
442
+ template=None,
443
+ plot_bgcolor=as_plotly_color(style["panel_fill"]),
444
+ paper_bgcolor=as_plotly_color(style["window_fill"]),
445
+ title=dict(text="95% family-wise confidence level",
446
+ x=0.5, xanchor="center",
447
+ font=dict(size=round(
448
+ 16 * get_option("main_size", 1)))))
449
+ return fig
395
450
 
396
451
 
397
452
  def _anova_means_plot(yv, gv, y_name, x_name, levels, jitter_x,
@@ -410,18 +465,18 @@ def _anova_means_plot(yv, gv, y_name, x_name, levels, jitter_x,
410
465
  x=xn, y=yv, mode="markers",
411
466
  marker=dict(symbol="circle", size=6,
412
467
  color=make_trans(pt, 0.85), opacity=1,
413
- line=dict(color=to_hex(pt), width=1)),
468
+ line=dict(color=as_plotly_color(pt), width=1)),
414
469
  hoverinfo="y", showlegend=False))
415
470
  means = [yv[gv == lv].mean() for lv in levels]
416
471
  for i, mval in enumerate(means):
417
472
  fig.add_shape(type="line", xref="x", yref="y",
418
473
  x0=-0.5, x1=len(levels) - 0.5,
419
474
  y0=mval, y1=mval, layer="below",
420
- line=dict(color=to_hex("gray70"), width=1))
475
+ line=dict(color=as_plotly_color("gray70"), width=1))
421
476
  fig.add_trace(go.Scatter(
422
477
  x=list(range(len(levels))), y=means, mode="markers",
423
478
  marker=dict(symbol="diamond", size=13,
424
- color=to_hex(get_option("fit_color",
479
+ color=as_plotly_color(get_option("fit_color",
425
480
  "#5C4032"))),
426
481
  hoverinfo="x+y", showlegend=False))
427
482
  axT2 = pretty(float(yv.min()), float(yv.max()))
@@ -431,13 +486,13 @@ def _anova_means_plot(yv, gv, y_name, x_name, levels, jitter_x,
431
486
  ticktext=levels, range=[-0.5, len(levels) - 0.5])
432
487
  ax_y = axis_num(y_name, axT2, axis_format(axT2, d))
433
488
  ax_y.update(showgrid=True,
434
- gridcolor=to_hex(style["grid_col"]),
489
+ gridcolor=as_plotly_color(style["grid_col"]),
435
490
  gridwidth=1, griddash="dot")
436
491
  fig.update_layout(
437
492
  xaxis=ax_x, yaxis=ax_y, shapes=fig.layout.shapes
438
493
  + tuple(plot_border()), template=None,
439
- plot_bgcolor=to_hex(style["panel_fill"]),
440
- paper_bgcolor=to_hex(style["window_fill"]),
494
+ plot_bgcolor=as_plotly_color(style["panel_fill"]),
495
+ paper_bgcolor=as_plotly_color(style["window_fill"]),
441
496
  title=dict(text="Scatterplot with Cell Means",
442
497
  x=0.5, xanchor="center",
443
498
  font=dict(size=round(
@@ -611,12 +666,12 @@ def _twoway(fit, yv, fvals, y_name, facs, flevs, n_keep, d,
611
666
  x1v, np.asarray(fit.fittedvalues), x2v,
612
667
  "Fitted", f1, f2, l1, l2, d, "Fitted Values")
613
668
 
614
- return ANOVAResults(
669
+ return show_plots(ANOVAResults(
615
670
  formula=formula, design=design, n_obs=n_obs,
616
671
  n_keep=n_keep, digits_d=d, response=y_name,
617
672
  factors=[f1, f2], cell_n=cell_n,
618
673
  marginal_means={f1: m1, f2: m2}, grand_mean=grand,
619
- anova=t, effects=eff, tukey=tukey, plots=plots)
674
+ anova=t, effects=eff, tukey=tukey, plots=plots))
620
675
 
621
676
 
622
677
  def _cat_line_fig(title, x_name, y_name, levels_x, series, d,
@@ -644,13 +699,13 @@ def _cat_line_fig(title, x_name, y_name, levels_x, series, d,
644
699
  range=[-0.4, len(levels_x) - 0.6])
645
700
  ax_y = axis_num(y_name, axT2, axis_format(axT2, d))
646
701
  ax_y.update(showgrid=True,
647
- gridcolor=to_hex(style["grid_col"]),
702
+ gridcolor=as_plotly_color(style["grid_col"]),
648
703
  gridwidth=1, griddash="dot")
649
704
  fig.update_layout(
650
705
  xaxis=ax_x, yaxis=ax_y, shapes=plot_border(),
651
706
  template=None, legend=dict(title=dict(text=legend_title)),
652
- plot_bgcolor=to_hex(style["panel_fill"]),
653
- paper_bgcolor=to_hex(style["window_fill"]),
707
+ plot_bgcolor=as_plotly_color(style["panel_fill"]),
708
+ paper_bgcolor=as_plotly_color(style["window_fill"]),
654
709
  title=dict(text=title, x=0.5, xanchor="center",
655
710
  font=dict(size=round(
656
711
  16 * get_option("main_size", 1)))))
@@ -678,3 +733,7 @@ def _blocks_plot(x1v, yvals, x2v, y_name, f1, f2, l1, l2, d,
678
733
  sub = dp[dp["b"] == b].set_index("a")["y"]
679
734
  series.append((b, [sub.get(a, np.nan) for a in l1]))
680
735
  return _cat_line_fig(title, f1, y_name, l1, series, d, f2)
736
+
737
+
738
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
739
+ ANOVA = file_output(ANOVA)