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/plt_plotly.py CHANGED
@@ -17,7 +17,7 @@ import plotly.graph_objects as go
17
17
 
18
18
  from .plotly_utils import (
19
19
  as_plotly_color, axis_base, axis_num, get_tick_fmt, make_trans,
20
- plot_border, plotly_style, sym_at, to_hex, x_grid, y_grid,
20
+ plot_border, plotly_style, marks, to_hex, x_grid, y_grid,
21
21
  )
22
22
  from .utils import get_option
23
23
 
@@ -47,6 +47,7 @@ def plt_plotly(groups, by_name=None,
47
47
  se_polys=None, se_fill=None,
48
48
  ellipses=None, ellipse_fill=None,
49
49
  ellipse_color=None, ellipse_lwd=1,
50
+ sizes=None, size_name=None,
50
51
  style_opts=None):
51
52
  """Scatterplot / time-series renderer for XY().
52
53
 
@@ -107,19 +108,34 @@ def plt_plotly(groups, by_name=None,
107
108
  hover = hover.replace(
108
109
  "<extra></extra>", f"<br>{by_name}: {nm}"
109
110
  "<extra></extra>")
111
+ # bubbles: a pixel diameter per point, its value in the hover
112
+ custom = None
113
+ if sizes is not None:
114
+ custom = sizes[i][1]
115
+ hover = hover.replace(
116
+ "<extra></extra>",
117
+ f"<br>{size_name}: %{{customdata:.{digits_d}f}}"
118
+ "<extra></extra>")
110
119
  marker = dict(
111
- symbol=sym_at(shape, i), size=px, sizemode="diameter",
120
+ size=px if sizes is None else sizes[i][0],
121
+ sizemode="diameter",
112
122
  color=make_trans(fills[i], pt_opacity), opacity=1,
113
- line=dict(color=to_hex(borders[i]), width=1),
114
- ) if "markers" in mode_pts else None
123
+ line=dict(color=as_plotly_color(borders[i]), width=1),
124
+ )
125
+ pts_kw = (marks(shape, i, mode_pts, marker)
126
+ if "markers" in mode_pts else dict(mode=mode_pts))
127
+ # a single series' line takes segment_color when it is given;
128
+ # several series keep the color that distinguishes them
129
+ ln_col = (style_opts["segment_color"]
130
+ if not has_groups and get_option("segment_color_set")
131
+ else borders[i])
115
132
  fig.add_trace(go.Scatter(
116
- x=xv, y=yv, mode=mode_pts,
133
+ x=xv, y=yv, **pts_kw,
117
134
  name=None if nm is None else str(nm),
118
135
  legendgroup=None if nm is None else str(nm),
119
- marker=marker,
120
- line=(dict(color=to_hex(borders[i]), width=ln_width)
136
+ line=(dict(color=as_plotly_color(ln_col), width=ln_width)
121
137
  if connect else None),
122
- hovertemplate=hover,
138
+ hovertemplate=hover, customdata=custom,
123
139
  # connected series show a legend-only line sample below
124
140
  showlegend=has_groups and not connect,
125
141
  ))
@@ -127,15 +143,15 @@ def plt_plotly(groups, by_name=None,
127
143
  fig.add_trace(go.Scatter(
128
144
  x=xv[:2], y=yv[:2], mode="lines",
129
145
  name=str(nm), legendgroup=str(nm),
130
- line=dict(color=to_hex(borders[i]), width=ln_width),
146
+ line=dict(color=as_plotly_color(borders[i]), width=ln_width),
131
147
  hoverinfo="skip", showlegend=True,
132
148
  ))
133
149
 
134
150
  # ellipses: border per group when grouped, else ellipse_color
135
151
  if ellipses:
136
152
  for k, (ex, ey) in enumerate(ellipses):
137
- edge = (to_hex(borders[k]) if has_groups
138
- else to_hex(ellipse_color))
153
+ edge = (as_plotly_color(borders[k % n_grp]) if has_groups
154
+ else as_plotly_color(ellipse_color))
139
155
  fig.add_trace(go.Scatter(
140
156
  x=ex, y=ey, mode="lines",
141
157
  line=dict(color=edge, width=ellipse_lwd),
@@ -171,8 +187,8 @@ def plt_plotly(groups, by_name=None,
171
187
  name="Fit" if single else f"Fit: {nm}",
172
188
  legendgroup="fit" if single else str(nm),
173
189
  line=dict(
174
- color=(to_hex(fit_color) if single
175
- else to_hex(fills[i])),
190
+ color=(as_plotly_color(fit_color) if single
191
+ else as_plotly_color(fills[i])),
176
192
  width=fit_lwd),
177
193
  hovertemplate=(
178
194
  f"{x_lab}: {xpart}<br>{lbl}: {ypart}"
@@ -185,7 +201,7 @@ def plt_plotly(groups, by_name=None,
185
201
  ax_x = axis_base()
186
202
  ax_x["title"]["text"] = x_lab
187
203
  ax_x.update(showgrid=True,
188
- gridcolor=to_hex(style_opts["grid_col"]),
204
+ gridcolor=as_plotly_color(style_opts["grid_col"]),
189
205
  gridwidth=1)
190
206
  shapes = y_grid(gridT2) + plot_border()
191
207
  else:
@@ -193,7 +209,7 @@ def plt_plotly(groups, by_name=None,
193
209
  shapes = x_grid(gridT1) + y_grid(gridT2) + plot_border()
194
210
  ax_y = axis_num(y_lab, ax["axT2"], ax["axL2"])
195
211
 
196
- leg_color = to_hex(style_opts["lab_color"])
212
+ leg_color = as_plotly_color(style_opts["lab_color"])
197
213
  fig.update_layout(
198
214
  xaxis=ax_x, yaxis=ax_y,
199
215
  shapes=shapes,
@@ -209,12 +225,12 @@ def plt_plotly(groups, by_name=None,
209
225
  family="Arial", color=leg_color),
210
226
  orientation="v", x=1.05, y=0.5,
211
227
  xanchor="left", yanchor="middle",
212
- bgcolor=to_hex(style_opts["window_fill"]),
228
+ bgcolor=as_plotly_color(style_opts["window_fill"]),
213
229
  bordercolor="#CCCCCC", borderwidth=1,
214
230
  itemsizing="constant",
215
231
  ),
216
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
217
- paper_bgcolor=to_hex(style_opts["window_fill"]),
232
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
233
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
218
234
  )
219
235
 
220
236
  if main:
lessPy/plt_smooth.py CHANGED
@@ -129,7 +129,7 @@ def plt_smooth(xv, yv, smooth_points, smooth_size, smooth_power,
129
129
  for ex, ey in ellipses or []:
130
130
  fig.add_trace(go.Scatter(
131
131
  x=ex, y=ey, mode="lines",
132
- line=dict(color=to_hex(ellipse_color),
132
+ line=dict(color=as_plotly_color(ellipse_color),
133
133
  width=ellipse_lwd),
134
134
  fill="toself",
135
135
  fillcolor=as_plotly_color(ellipse_fill),
@@ -145,7 +145,7 @@ def plt_smooth(xv, yv, smooth_points, smooth_size, smooth_power,
145
145
  fig.add_trace(go.Scatter(
146
146
  x=fl["x"], y=fl["y"], mode="lines", name="Fit",
147
147
  legendgroup="fit",
148
- line=dict(color=to_hex(fit_color), width=fit_lwd),
148
+ line=dict(color=as_plotly_color(fit_color), width=fit_lwd),
149
149
  hoverinfo="skip", showlegend=True))
150
150
 
151
151
  ax_x = axis_num(x_lab, ax["axT1"], ax["axL1"])
@@ -156,8 +156,8 @@ def plt_smooth(xv, yv, smooth_points, smooth_size, smooth_power,
156
156
  xaxis=ax_x, yaxis=ax_y,
157
157
  shapes=x_grid(gridT1) + y_grid(gridT2) + plot_border(),
158
158
  template=None,
159
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
160
- paper_bgcolor=to_hex(style_opts["window_fill"]),
159
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
160
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
161
161
  )
162
162
 
163
163
  if main:
lessPy/plt_time.py CHANGED
@@ -56,11 +56,18 @@ def _agg_one(dser, yser, ts_unit, aggfun):
56
56
  per = dser
57
57
  else:
58
58
  per = dser.dt.to_period(_PERIOD_FREQ[ts_unit])
59
- # trailing partial period: last date short of period end
59
+ # trailing partial period: its last date short of the period
60
+ # end AND fewer observations than the median of the earlier
61
+ # periods, so data dated at period starts keeps its complete
62
+ # final period. R analog: ts_truncate() (plt.time.R)
60
63
  last_per = per.iloc[int(np.argmax(dser.to_numpy()))]
61
64
  if dser.max() < last_per.end_time.normalize():
62
- keep = (per != last_per).to_numpy()
63
- dser, yser, per = dser[keep], yser[keep], per[keep]
65
+ n_per = per.value_counts()
66
+ others = n_per.drop(last_per)
67
+ n_full = float(np.median(others)) if len(others) else 0
68
+ if n_per[last_per] < n_full:
69
+ keep = (per != last_per).to_numpy()
70
+ dser, yser, per = dser[keep], yser[keep], per[keep]
64
71
  if len(dser) == 0:
65
72
  return (np.array([], dtype="datetime64[ns]"),
66
73
  np.array([]))
lessPy/prob_norm.py CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  import numpy as np
10
10
 
11
- from .utils import fmt
11
+ from .utils import fmt, file_output, show_plots
12
12
 
13
13
  _FILL_NRM = "#E8E8E8" # grey91
14
14
  _FILL_INT = "#9FB6CD" # slategray3
@@ -57,8 +57,8 @@ def prob_norm(lo=None, hi=None, mu=0, sigma=1, nrm_color="black",
57
57
 
58
58
  print(f"Probability: {prob}")
59
59
 
60
- return ProbNormResults(prob=prob, lo=lo_v, hi=hi_v, mu=mu,
61
- sigma=sigma, plots={"norm": fig})
60
+ return show_plots(ProbNormResults(prob=prob, lo=lo_v, hi=hi_v, mu=mu,
61
+ sigma=sigma, plots={"norm": fig}))
62
62
 
63
63
 
64
64
  def _plot(lo, hi, lo_lbl, hi_lbl, mu, sigma, prob, nrm_color,
@@ -109,3 +109,7 @@ def _plot(lo, hi, lo_lbl, hi_lbl, mu, sigma, prob, nrm_color,
109
109
  showarrow=False,
110
110
  font=dict(size=11))
111
111
  return fig
112
+
113
+
114
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
115
+ prob_norm = file_output(prob_norm)
lessPy/prob_tcut.py CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  import numpy as np
11
11
 
12
- from .utils import fmt
12
+ from .utils import fmt, file_output, show_plots
13
13
 
14
14
  _BG = "#F9F9FC" # rgb(249,249,252)
15
15
  _TAIL = "#8B475D" # palevioletred4
@@ -51,8 +51,8 @@ def prob_tcut(df, alpha=0.05, digits_d=3, y_axis=False,
51
51
  fill, color_tail, nrm_color, color_t)
52
52
 
53
53
  print(f"Probability: {cutoff}")
54
- return ProbTcutResults(cutoff=cutoff, df=df, alpha=alpha,
55
- plots={"tcut": fig})
54
+ return show_plots(ProbTcutResults(cutoff=cutoff, df=df, alpha=alpha,
55
+ plots={"tcut": fig}))
56
56
 
57
57
 
58
58
  def _cut_line(fig, x, top, color):
@@ -129,3 +129,7 @@ def _plot(df, alpha, t_lo, t_hi, n_lo, n_hi, digits_d, y_axis,
129
129
  bordercolor="black", borderwidth=0.5,
130
130
  font=dict(size=10)))
131
131
  return fig
132
+
133
+
134
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
135
+ prob_tcut = file_output(prob_tcut)
lessPy/prob_znorm.py CHANGED
@@ -11,6 +11,8 @@
11
11
 
12
12
  import numpy as np
13
13
 
14
+ from .utils import file_output, show_plots
15
+
14
16
 
15
17
  class ProbZnormResults:
16
18
  """Result of prob_znorm(): mu/sigma and the plotly figure in
@@ -46,7 +48,7 @@ def prob_znorm(mu=0, sigma=1, color_border="gray10", r=0.10,
46
48
  f"{round(b * 255)},{a})"
47
49
 
48
50
  fig = _plot(mu, sigma, border, fill, main, y_axis, z)
49
- return ProbZnormResults(mu=mu, sigma=sigma, plots={"znorm": fig})
51
+ return show_plots(ProbZnormResults(mu=mu, sigma=sigma, plots={"znorm": fig}))
50
52
 
51
53
 
52
54
  def _gray_to_hex(color):
@@ -108,3 +110,7 @@ def _plot(mu, sigma, border, fill, main, y_axis, z):
108
110
  showarrow=False,
109
111
  font=dict(size=11))
110
112
  return fig
113
+
114
+
115
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
116
+ prob_znorm = file_output(prob_znorm)
lessPy/profile_plotly.py CHANGED
@@ -21,6 +21,7 @@ import plotly.graph_objects as go
21
21
 
22
22
  from .utils import get_option
23
23
  from .plotly_utils import (
24
+ as_plotly_color,
24
25
  axis_num, facet_layout, make_trans, plot_border, plotly_style,
25
26
  to_hex, y_grid,
26
27
  )
@@ -75,9 +76,9 @@ def profile_facet_plotly(cells, x_levels, series, y_tick, y_lab_tick,
75
76
  marker=dict(symbol="circle", size=px,
76
77
  sizemode="diameter",
77
78
  color=make_trans(fills[j], 1),
78
- line=dict(color=to_hex(fills[j]),
79
+ line=dict(color=as_plotly_color(fills[j]),
79
80
  width=1)),
80
- line=dict(color=to_hex(fills[j]), width=ln_width),
81
+ line=dict(color=as_plotly_color(fills[j]), width=ln_width),
81
82
  hovertemplate=hover,
82
83
  showlegend=grouped and i == 0,
83
84
  ))
@@ -114,8 +115,8 @@ def profile_facet_plotly(cells, x_levels, series, y_tick, y_lab_tick,
114
115
  yanchor="top", font=dict(size=title_size))
115
116
  if main else None),
116
117
  template=None,
117
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
118
- paper_bgcolor=to_hex(style_opts["window_fill"]),
118
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
119
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
119
120
  **axes,
120
121
  )
121
122
  return fig
lessPy/radar_plotly.py CHANGED
@@ -20,6 +20,7 @@ import plotly.graph_objects as go
20
20
 
21
21
  from .utils import get_option
22
22
  from .plotly_utils import (
23
+ as_plotly_color,
23
24
  BASE_COLORS, facet_layout, make_trans, plotly_style, to_hex,
24
25
  )
25
26
 
@@ -182,7 +183,7 @@ def radar_plotly(x=None, x_name=None, by_name=None, main=None,
182
183
  text=main, x=0.5, xanchor="center",
183
184
  y=0.97, yanchor="top",
184
185
  font=dict(size=title_size,
185
- color=to_hex(get_option("lab_color",
186
+ color=as_plotly_color(get_option("lab_color",
186
187
  "black")))),
187
188
  margin=dict(t=round(title_size * 2.2), b=10,
188
189
  l=20 if n_fac == 1 else r_margin,
@@ -191,11 +192,11 @@ def radar_plotly(x=None, x_name=None, by_name=None, main=None,
191
192
  annotations=anns,
192
193
  legend=dict(
193
194
  x=1.02, xanchor="left", y=1.0, yanchor="top",
194
- bordercolor=to_hex(style_opts["panel_border"]),
195
+ bordercolor=as_plotly_color(style_opts["panel_border"]),
195
196
  borderwidth=1,
196
197
  font=dict(size=round(18 * ax_cex)),
197
198
  ),
198
199
  template=None,
199
- paper_bgcolor=to_hex(style_opts["window_fill"]),
200
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
200
201
  )
201
202
  return fig