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/bc_items_plotly.py CHANGED
@@ -20,7 +20,7 @@ from .utils import get_option, pretty
20
20
  from .plotly_utils import (
21
21
  as_plotly_color, auto_text_color, axis_cat, axis_format,
22
22
  axis_num, legend_style, plot_border, plotly_style, to_hex,
23
- x_grid,
23
+ x_grid, y_grid,
24
24
  )
25
25
 
26
26
  # theme -> the two sequential palettes of the divergent fill
@@ -91,24 +91,31 @@ def items_table(cols, names):
91
91
  return frq, wm, numeric
92
92
 
93
93
 
94
- def items_stats_lines(frq, wm, title, numeric=True):
94
+ def items_stats_lines(frq, wm, title, numeric=True, with_sum=False):
95
95
  """'Frequencies of Responses by Variable': one row per item,
96
96
  its counts and its mean. R analog: .prntbl(t(x), 0) with the
97
- Mean column of .bc.main() multi"""
98
- t = frq.T
97
+ Mean column of .bc.main() multi. with_sum adds the Sum column of
98
+ the bubble plot frequency matrix, whose Mean column follows at
99
+ one space and is sized to the mean at three decimals, as
100
+ .dpmat.main() writes it"""
101
+ t = frq.T.copy()
102
+ if with_sum:
103
+ t["Sum"] = t.sum(axis=1)
99
104
  rows = [str(r) for r in t.index]
100
105
  max_c1 = max(len(r) for r in rows) + 2
101
106
  widths = [max(4, max(len(str(c)),
102
107
  max(len(f"{v:.0f}") for v in t[c])) + 1)
103
108
  for c in t.columns]
104
- mx = max(len(f"{round(v, 2):.15g}") for v in wm if np.isfinite(v))
109
+ mx = max(len(f"{round(v, 3 if with_sum else 2):.15g}")
110
+ for v in wm if np.isfinite(v))
111
+ sep = " " if with_sum else " "
105
112
  hdr = " " * max_c1 + "".join(str(c).rjust(w)
106
113
  for c, w in zip(t.columns, widths))
107
- lines = [title, "", hdr + " " + "Mean".rjust(mx + 1)]
114
+ lines = [title, "", hdr + sep + "Mean".rjust(mx + 1)]
108
115
  for r in t.index:
109
116
  ln = (" " + str(r)).rjust(max_c1) + "".join(
110
117
  f"{v:.0f}".rjust(w) for v, w in zip(t.loc[r], widths))
111
- lines.append(ln + " " + f"{wm[r]:.3f}".rjust(mx + 1))
118
+ lines.append(ln + sep + f"{wm[r]:.3f}".rjust(mx + 1))
112
119
  if not numeric:
113
120
  lines += ["", "Computation of the mean based on coding "
114
121
  "response categories from 1 to "
@@ -120,9 +127,11 @@ def bc_items_plotly(frq, order, fill, labels="%", labels_size=None,
120
127
  labels_cut=0.04, stack100=False, x_lab="",
121
128
  y_lab="", legend_title="Responses", main=None,
122
129
  digits_d=0, axis_fmt="K", axis_x_pre="",
123
- rotate_x=0, rotate_y=0, style_opts=None):
124
- """One horizontal bar per item, stacked by response. frq:
125
- responses x items counts; order: the items bottom to top."""
130
+ rotate_x=0, rotate_y=0, horiz=True,
131
+ style_opts=None):
132
+ """One bar per item, stacked by response. frq: responses x items
133
+ counts; order: the items bottom to top, or left to right when
134
+ horiz=False (the vertical chart)."""
126
135
  if style_opts is None:
127
136
  style_opts = plotly_style()
128
137
  cnt = frq[order].to_numpy(dtype=float)
@@ -147,7 +156,9 @@ def bc_items_plotly(frq, order, fill, labels="%", labels_size=None,
147
156
  f"{c:.0f}")
148
157
  for s, c in zip(share[i], cnt[i])]
149
158
  fig.add_trace(go.Bar(
150
- x=mat[i], y=list(order), orientation="h", name=str(r),
159
+ x=mat[i] if horiz else list(order),
160
+ y=list(order) if horiz else mat[i],
161
+ orientation="h" if horiz else "v", name=str(r),
151
162
  marker=dict(color=fills[i % len(fills)],
152
163
  line=dict(width=0)),
153
164
  text=txt, textposition="inside",
@@ -155,7 +166,8 @@ def bc_items_plotly(frq, order, fill, labels="%", labels_size=None,
155
166
  textfont=dict(size=txt_size,
156
167
  color=txt_cols[i % len(txt_cols)]),
157
168
  customdata=np.stack([cnt[i], share[i]], axis=-1),
158
- hovertemplate=(f"%{{y}}<br>{legend_title}: {r}"
169
+ hovertemplate=(("%{y}" if horiz else "%{x}")
170
+ + f"<br>{legend_title}: {r}"
159
171
  "<br>Count: %{customdata[0]:.0f}"
160
172
  "<br>% of item: %{customdata[1]:.1%}"
161
173
  "<extra></extra>"),
@@ -167,11 +179,12 @@ def bc_items_plotly(frq, order, fill, labels="%", labels_size=None,
167
179
  d = 2
168
180
  else:
169
181
  d = digits_d
170
- x_ax = axis_num(x_lab, axT, axis_format(axT, d, axis_fmt,
171
- axis_x_pre))
172
- x_ax.update(range=[0, axT[-1] * (1 if stack100 else 1.02)])
173
- y_ax = axis_cat(y_lab)
174
- y_ax.update(categoryorder="array", categoryarray=list(order))
182
+ val_ax = axis_num(x_lab if horiz else y_lab, axT,
183
+ axis_format(axT, d, axis_fmt, axis_x_pre))
184
+ val_ax.update(range=[0, axT[-1] * (1 if stack100 else 1.02)])
185
+ cat_ax = axis_cat(y_lab if horiz else x_lab)
186
+ cat_ax.update(categoryorder="array", categoryarray=list(order))
187
+ x_ax, y_ax = (val_ax, cat_ax) if horiz else (cat_ax, val_ax)
175
188
  if rotate_x:
176
189
  x_ax["tickangle"] = -rotate_x
177
190
  if rotate_y:
@@ -181,10 +194,10 @@ def bc_items_plotly(frq, order, fill, labels="%", labels_size=None,
181
194
  fig.update_layout(
182
195
  barmode="stack", bargap=0.2,
183
196
  xaxis=x_ax, yaxis=y_ax,
184
- shapes=x_grid(axT) + plot_border(),
197
+ shapes=(x_grid(axT) if horiz else y_grid(axT)) + plot_border(),
185
198
  legend=leg, template=None,
186
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
187
- paper_bgcolor=to_hex(style_opts["window_fill"]),
199
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
200
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
188
201
  )
189
202
  if main:
190
203
  title_size = round(16 * get_option("main_size", 1))
lessPy/bc_plotly.py CHANGED
@@ -475,8 +475,8 @@ def bc_plotly(x, x_name=None, y_name=None, by_name=None,
475
475
  plt.update_layout(bargroupgap=bargroupgap)
476
476
 
477
477
  plt.update_layout(
478
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
479
- paper_bgcolor=to_hex(style_opts["window_fill"]),
478
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
479
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
480
480
  )
481
481
 
482
482
  if by_name:
@@ -506,7 +506,7 @@ def bc_facet_plotly(x, x_name=None, facet_name=None,
506
506
  n_col=1, axis_fmt="K", axis_x_pre="",
507
507
  rotate_x=0, rotate_y=0,
508
508
  by_tbls=None, by_name=None, beside=False,
509
- val_name=None, legend_title=None,
509
+ val_name=None, legend_title=None, horiz=True,
510
510
  style_opts=None):
511
511
  """Faceted bar chart: one panel per facet level, on a shared
512
512
  value axis with horizontal bars, as in the lattice Trellis bar
@@ -586,7 +586,8 @@ def bc_facet_plotly(x, x_name=None, facet_name=None,
586
586
  f"<br>{facet_name}: {lv}")
587
587
  for cc, v in zip(cats, row)]
588
588
  fig.add_trace(go.Bar(
589
- x=row, y=cats, orientation="h",
589
+ x=row if horiz else cats, y=cats if horiz else row,
590
+ orientation="h" if horiz else "v",
590
591
  marker=dict(color=fill_vec, opacity=alpha_fill,
591
592
  line=dict(color=border_vec, width=1)),
592
593
  hoverinfo="text", hovertext=hover,
@@ -604,24 +605,40 @@ def bc_facet_plotly(x, x_name=None, facet_name=None,
604
605
  f"<br>{facet_name}: {lv}")
605
606
  for cc, v in zip(cats, vals)]
606
607
  fig.add_trace(go.Bar(
607
- x=vals, y=cats, orientation="h", name=b,
608
+ x=vals if horiz else cats, y=cats if horiz else vals,
609
+ orientation="h" if horiz else "v", name=b,
608
610
  legendgroup=b, showlegend=(i == 0),
609
611
  marker=dict(color=clr, opacity=alpha_fill,
610
612
  line=dict(color=brd, width=1)),
611
613
  hoverinfo="text", hovertext=hover,
612
614
  ), row=r, col=c)
613
615
 
614
- finish_facet(fig, fac_levels, ax, x_lab, y_lab, gridT1=axT1,
615
- style_opts=style_opts, y_cat=cats, n_col=n_col)
616
+ if horiz:
617
+ finish_facet(fig, fac_levels, ax, x_lab, y_lab, gridT1=axT1,
618
+ style_opts=style_opts, y_cat=cats, n_col=n_col)
619
+ else:
620
+ # the vertical chart: categories along x, the shared value
621
+ # scale up the side of every panel
622
+ finish_facet(fig, fac_levels,
623
+ {"axT2": axT1, "axL2": ax["axL1"]},
624
+ y_lab, x_lab, gridT1=None, style_opts=style_opts,
625
+ n_col=n_col, x_cat=cats)
616
626
  if grouped:
617
627
  fig.update_layout(
618
628
  barmode="group" if beside else "stack",
619
629
  showlegend=True,
620
630
  legend=dict(title=dict(text=(legend_title
621
631
  if legend_title is not None
622
- else by_name)),
632
+ else by_name),
633
+ font=dict(color=as_plotly_color(
634
+ style_opts["lab_color"]))),
635
+ font=dict(color=as_plotly_color(
636
+ style_opts["lab_color"])),
623
637
  traceorder="normal"))
624
- fig.update_xaxes(range=[axT1[0], axT1[-1]]) # includes zero
638
+ if horiz:
639
+ fig.update_xaxes(range=[axT1[0], axT1[-1]]) # includes zero
640
+ else:
641
+ fig.update_yaxes(range=[axT1[0], axT1[-1]])
625
642
  if rotate_x:
626
643
  fig.update_xaxes(tickangle=-rotate_x)
627
644
  if rotate_y:
@@ -633,7 +650,7 @@ def bc_facet_plotly(x, x_name=None, facet_name=None,
633
650
  title=dict(text=main, x=0.5, xanchor="center",
634
651
  y=0.99, yanchor="top",
635
652
  font=dict(size=title_size,
636
- color=to_hex(get_option(
653
+ color=as_plotly_color(get_option(
637
654
  "lab_color", "black")))),
638
655
  margin=dict(t=round(title_size * 2.2)))
639
656
  return fig
lessPy/bubble_plotly.py CHANGED
@@ -22,6 +22,7 @@ import plotly.graph_objects as go
22
22
 
23
23
  from .utils import fmt, get_option
24
24
  from .plotly_utils import (
25
+ as_plotly_color,
25
26
  BASE_COLORS, contrast_text_for_hex, facet_layout, make_trans,
26
27
  plotly_style, to_hex,
27
28
  )
@@ -63,6 +64,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
63
64
  labels_decimals=None,
64
65
  label_min_px=26, label_autocontrast=True,
65
66
  facet_tbls=None, facet_name=None, n_col=None,
67
+ shares=False, label_min_value=None,
66
68
  style_opts=None):
67
69
 
68
70
  if labels is None:
@@ -98,8 +100,11 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
98
100
 
99
101
  # "prop" plots proportions, which digits_d (0 for counts)
100
102
  # would flatten to "0"
103
+ # a percentage of a proportion reads in whole numbers, as the
104
+ # percentages of counts do
101
105
  lbl_d = (int(labels_decimals) if labels_decimals is not None
102
106
  else (2 if labels == "prop"
107
+ else 0 if (shares and labels == "%")
103
108
  else max(0, int(digits_d))))
104
109
  trace_mode = "markers" if labels == "off" else "markers+text"
105
110
  # None = the default (R's labels_position %||% "in")
@@ -125,7 +130,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
125
130
  title=dict(text=main, x=0.5, xanchor="center",
126
131
  y=0.98, yanchor="top",
127
132
  font=dict(size=title_size,
128
- color=to_hex(get_option(
133
+ color=as_plotly_color(get_option(
129
134
  "lab_color", "black")))),
130
135
  margin=dict(t=round(title_size * 2.2),
131
136
  r=25, b=30, l=25))
@@ -162,7 +167,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
162
167
 
163
168
  target_r = 0.35
164
169
  y_top = target_r * 1.20
165
- seg_color = to_hex(style_opts["grid_color"])
170
+ seg_color = as_plotly_color(style_opts["grid_color"])
166
171
  hover = (f"{x_name}: %{{customdata.xcat}}"
167
172
  f"<br>{y_name}: %{{hovertext}}"
168
173
  f"<br>% of {x_name}: %{{customdata.pct_x:.1%}}"
@@ -213,7 +218,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
213
218
  size=diam_px.tolist(),
214
219
  sizemode="diameter",
215
220
  color=fill_rgba,
216
- line=dict(color=to_hex(border), width=1),
221
+ line=dict(color=as_plotly_color(border), width=1),
217
222
  sizemin=12,
218
223
  ),
219
224
  text=label_show,
@@ -260,8 +265,8 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
260
265
  b=8, l=20, r=20),
261
266
  showlegend=False,
262
267
  template=None,
263
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
264
- paper_bgcolor=to_hex(style_opts["window_fill"]),
268
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
269
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
265
270
  **axes,
266
271
  )
267
272
  if main:
@@ -269,7 +274,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
269
274
  text=main, x=0.5, xanchor="center",
270
275
  y=0.98, yanchor="top",
271
276
  font=dict(size=title_size,
272
- color=to_hex(get_option("lab_color",
277
+ color=as_plotly_color(get_option("lab_color",
273
278
  "black")))))
274
279
  return fig
275
280
 
@@ -325,7 +330,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
325
330
  size=diam_px.tolist(),
326
331
  sizemode="diameter",
327
332
  color=fill_rgba,
328
- line=dict(color=to_hex(border), width=1),
333
+ line=dict(color=as_plotly_color(border), width=1),
329
334
  sizemin=12,
330
335
  ),
331
336
  text=label_show,
@@ -339,7 +344,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
339
344
  target_r = 0.35
340
345
  radius_data = (diam_px / max_diam) * target_r
341
346
  y_top = target_r * 1.20
342
- seg_color = to_hex(style_opts["grid_color"])
347
+ seg_color = as_plotly_color(style_opts["grid_color"])
343
348
  stems = [dict(type="line", xref="x", yref="y",
344
349
  x0=i, x1=i, y0=-1, y1=-float(radius_data[i]),
345
350
  line=dict(color=seg_color, width=1),
@@ -363,8 +368,8 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
363
368
  range=[-1, y_top]),
364
369
  shapes=stems,
365
370
  template=None,
366
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
367
- paper_bgcolor=to_hex(style_opts["window_fill"]),
371
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
372
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
368
373
  )
369
374
  title_layout(fig)
370
375
  return fig
@@ -377,6 +382,11 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
377
382
 
378
383
  total = np.nansum(mat)
379
384
  share_tot = mat / total if total > 0 else np.zeros(mat.shape)
385
+ # values that are already proportions, each by group's distribution
386
+ # over x, are their own percentages: a share of the table total
387
+ # would divide them again by the number of groups
388
+ if shares:
389
+ share_tot = np.nan_to_num(mat)
380
390
  col_tot = np.nansum(mat, axis=0)
381
391
  with np.errstate(invalid="ignore", divide="ignore"):
382
392
  share_x = np.where(col_tot > 0, mat / col_tot, 0.0)
@@ -407,8 +417,14 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
407
417
  else:
408
418
  txt = _label_text(row, share_tot[i], labels, digits_d,
409
419
  lbl_d)
410
- label_show = [t if np.isfinite(dp) and dp >= label_min_px
411
- else "" for t, dp in zip(txt, diam_px)]
420
+ # a bubble labels its value when it is large enough to hold
421
+ # it; label_min_value states that as a value instead, as
422
+ # R's bubble plot frequency matrix does (power/2.5 * max)
423
+ label_show = ([t if np.isfinite(v) and v > label_min_value
424
+ else "" for t, v in zip(txt, row)]
425
+ if label_min_value is not None else
426
+ [t if np.isfinite(dp) and dp >= label_min_px
427
+ else "" for t, dp in zip(txt, diam_px)])
412
428
  customdata = [dict(xcat=c, bycat=g, pct_x=float(px),
413
429
  pct_tot=float(pt))
414
430
  for c, px, pt in zip(cats, share_x[i],
@@ -425,7 +441,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
425
441
  size=diam_px.tolist(),
426
442
  sizemode="diameter",
427
443
  color=grp_rgba[i],
428
- line=dict(color=to_hex(border), width=1),
444
+ line=dict(color=as_plotly_color(border), width=1),
429
445
  ),
430
446
  text=label_show,
431
447
  textposition=txt_pos,
@@ -442,7 +458,7 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
442
458
  title=dict(text=x_lab if x_lab is not None else x_name,
443
459
  font=dict(size=lab_font)),
444
460
  showgrid=True,
445
- gridcolor=to_hex(style_opts["grid_color"]),
461
+ gridcolor=as_plotly_color(style_opts["grid_color"]),
446
462
  gridwidth=1,
447
463
  zeroline=False,
448
464
  tickfont=dict(size=tick_font),
@@ -460,11 +476,11 @@ def bubble_plotly(x=None, x_name=None, y_name=None, by_name=None,
460
476
  template=None,
461
477
  shapes=[dict(type="rect", xref="paper", yref="paper",
462
478
  x0=0, x1=1, y0=0, y1=1,
463
- line=dict(color=to_hex(
479
+ line=dict(color=as_plotly_color(
464
480
  style_opts["panel_border"]), width=1),
465
481
  layer="below")],
466
- plot_bgcolor=to_hex(style_opts["panel_fill"]),
467
- paper_bgcolor=to_hex(style_opts["window_fill"]),
482
+ plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
483
+ paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
468
484
  )
469
485
  title_layout(fig)
470
486
  return fig
lessPy/corCFA.py CHANGED
@@ -19,7 +19,7 @@ import re
19
19
  import numpy as np
20
20
  import pandas as pd
21
21
 
22
- from .utils import fmt, get_option
22
+ from .utils import fmt, get_option, file_output, show_plots
23
23
 
24
24
 
25
25
  def _mimm(R, cuts, NItems, NF, Iter):
@@ -203,10 +203,10 @@ def corCFA(R, model=None, factors=None, min_cor=0.10,
203
203
  plots = {}
204
204
  if heat_map:
205
205
  plots["heatmap"] = _cfa_heatmap(Rout, items, fcols)
206
- return corCFAResults(
206
+ return show_plots(corCFAResults(
207
207
  if_cor=if_cor, ff_cor=ff_cor, communalities=commun,
208
208
  alpha=alpha, omega=omega, pred=pred, resid=res,
209
- plots=plots)
209
+ plots=plots))
210
210
 
211
211
 
212
212
  def _cfa_text(items, fcols, cuts, alpha, omega, iter, if_cor,
@@ -299,7 +299,7 @@ def _lavaan(fcols, cuts, items):
299
299
 
300
300
  def _cfa_heatmap(Rout, items, fcols):
301
301
  import plotly.graph_objects as go
302
- from .plotly_utils import plotly_style, to_hex
302
+ from .plotly_utils import as_plotly_color, plotly_style, to_hex
303
303
  labels = items + fcols
304
304
  style = plotly_style()
305
305
  fig = go.Figure(go.Heatmap(
@@ -308,9 +308,13 @@ def _cfa_heatmap(Rout, items, fcols):
308
308
  colorbar=dict(title="r")))
309
309
  fig.update_yaxes(autorange="reversed")
310
310
  fig.update_layout(
311
- template=None, paper_bgcolor=to_hex(style["window_fill"]),
311
+ template=None, paper_bgcolor=as_plotly_color(style["window_fill"]),
312
312
  title=dict(text="Item / Factor Correlations", x=0.5,
313
313
  xanchor="center",
314
314
  font=dict(size=round(
315
315
  16 * get_option("main_size", 1)))))
316
316
  return fig
317
+
318
+
319
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
320
+ corCFA = file_output(corCFA)
lessPy/corProp.py CHANGED
@@ -11,7 +11,7 @@
11
11
  import numpy as np
12
12
  import pandas as pd
13
13
 
14
- from .utils import get_option
14
+ from .utils import get_option, file_output, show_plots
15
15
 
16
16
 
17
17
  def corProp(R, main=None, heat_map=True):
@@ -48,13 +48,13 @@ def corProp(R, main=None, heat_map=True):
48
48
  if heat_map:
49
49
  plots["heatmap"] = _heatmap(out, main)
50
50
  out.attrs["plots"] = plots
51
- return out
51
+ return show_plots(out)
52
52
 
53
53
 
54
54
  def _heatmap(df, main):
55
55
  import plotly.graph_objects as go
56
56
 
57
- from .plotly_utils import plotly_style, to_hex
57
+ from .plotly_utils import as_plotly_color, plotly_style, to_hex
58
58
  labels = list(df.columns)
59
59
  Z = df.to_numpy(dtype=float).copy()
60
60
  np.fill_diagonal(Z, np.nan) # ignore the diagonal
@@ -65,9 +65,13 @@ def _heatmap(df, main):
65
65
  colorbar=dict(title="prop")))
66
66
  fig.update_yaxes(autorange="reversed")
67
67
  fig.update_layout(
68
- template=None, paper_bgcolor=to_hex(style["window_fill"]),
68
+ template=None, paper_bgcolor=as_plotly_color(style["window_fill"]),
69
69
  title=dict(text=main or "Item Proportionalities", x=0.5,
70
70
  xanchor="center",
71
71
  font=dict(size=round(
72
72
  16 * get_option("main_size", 1)))))
73
73
  return fig
74
+
75
+
76
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
77
+ corProp = file_output(corProp)
lessPy/corReflect.py CHANGED
@@ -11,7 +11,7 @@
11
11
  import numpy as np
12
12
  import pandas as pd
13
13
 
14
- from .utils import get_option
14
+ from .utils import get_option, file_output, show_plots
15
15
 
16
16
 
17
17
  def corReflect(R, vars, main=None, heat_map=True):
@@ -47,13 +47,13 @@ def corReflect(R, vars, main=None, heat_map=True):
47
47
  if heat_map:
48
48
  plots["heatmap"] = _heatmap(out, main)
49
49
  out.attrs["plots"] = plots
50
- return out
50
+ return show_plots(out)
51
51
 
52
52
 
53
53
  def _heatmap(df, main):
54
54
  import plotly.graph_objects as go
55
55
 
56
- from .plotly_utils import plotly_style, to_hex
56
+ from .plotly_utils import as_plotly_color, plotly_style, to_hex
57
57
  labels = list(df.columns)
58
58
  Z = df.to_numpy(dtype=float).copy()
59
59
  np.fill_diagonal(Z, np.nan)
@@ -64,9 +64,13 @@ def _heatmap(df, main):
64
64
  colorbar=dict(title="r")))
65
65
  fig.update_yaxes(autorange="reversed")
66
66
  fig.update_layout(
67
- template=None, paper_bgcolor=to_hex(style["window_fill"]),
67
+ template=None, paper_bgcolor=as_plotly_color(style["window_fill"]),
68
68
  title=dict(text=main or "With Reflected Item Coefficients",
69
69
  x=0.5, xanchor="center",
70
70
  font=dict(size=round(
71
71
  16 * get_option("main_size", 1)))))
72
72
  return fig
73
+
74
+
75
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
76
+ corReflect = file_output(corReflect)
lessPy/corReorder.py CHANGED
@@ -11,7 +11,7 @@
11
11
  import numpy as np
12
12
  import pandas as pd
13
13
 
14
- from .utils import get_option
14
+ from .utils import get_option, file_output, show_plots
15
15
 
16
16
  # R hclust method -> scipy linkage method. scipy 'ward' is R's
17
17
  # ward.D2 (squared updates); ward.D has no scipy equivalent, so
@@ -70,7 +70,7 @@ def corReorder(R, order="hclust", hclust_type="complete",
70
70
  pass
71
71
  out.attrs["plots"] = plots
72
72
  out.attrs["order"] = label
73
- return out
73
+ return show_plots(out)
74
74
 
75
75
 
76
76
  def _chain(S, nv, first):
@@ -130,7 +130,7 @@ def _apply_diag(M):
130
130
 
131
131
  def _heatmap(df, diagonal_new, main):
132
132
  import plotly.graph_objects as go
133
- from .plotly_utils import plotly_style, to_hex
133
+ from .plotly_utils import as_plotly_color, plotly_style, to_hex
134
134
  Z = df.to_numpy(dtype=float).copy()
135
135
  if diagonal_new:
136
136
  Z = _apply_diag(Z)
@@ -142,7 +142,7 @@ def _heatmap(df, diagonal_new, main):
142
142
  colorbar=dict(title="r")))
143
143
  fig.update_yaxes(autorange="reversed")
144
144
  fig.update_layout(
145
- template=None, paper_bgcolor=to_hex(style["window_fill"]),
145
+ template=None, paper_bgcolor=as_plotly_color(style["window_fill"]),
146
146
  title=dict(text=main or "Reordered Correlations", x=0.5,
147
147
  xanchor="center",
148
148
  font=dict(size=round(
@@ -159,3 +159,7 @@ def _dendrogram(Z, names, label):
159
159
  title=dict(text="Cluster Dendrogram", x=0.5,
160
160
  xanchor="center"))
161
161
  return fig
162
+
163
+
164
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
165
+ corReorder = file_output(corReorder)
lessPy/corScree.py CHANGED
@@ -9,9 +9,9 @@ import numpy as np
9
9
  import pandas as pd
10
10
 
11
11
  from .plotly_utils import (
12
- axis_format, axis_num, plot_border, plotly_style, to_hex,
12
+ as_plotly_color, axis_format, axis_num, plot_border, plotly_style, to_hex,
13
13
  x_grid)
14
- from .utils import fmt, get_option, pretty
14
+ from .utils import fmt, get_option, pretty, file_output, show_plots
15
15
 
16
16
 
17
17
  class corScreeResults:
@@ -54,8 +54,8 @@ def corScree(R, main=None):
54
54
  "differences": _scree_plot(
55
55
  ev_diff, "Differences of Successive Eigenvalues",
56
56
  main)}
57
- return corScreeResults(eigenvalues=ev, differences=ev_diff,
58
- plots=plots)
57
+ return show_plots(corScreeResults(eigenvalues=ev, differences=ev_diff,
58
+ plots=plots))
59
59
 
60
60
 
61
61
  def _scree_plot(y, y_lab, main):
@@ -64,7 +64,7 @@ def _scree_plot(y, y_lab, main):
64
64
  import plotly.graph_objects as go
65
65
  style = plotly_style()
66
66
  x = np.arange(1, len(y) + 1)
67
- col = to_hex(get_option("fit_color", "#5C4032"))
67
+ col = as_plotly_color(get_option("fit_color", "#5C4032"))
68
68
  fig = go.Figure(go.Scatter(
69
69
  x=x, y=y, mode="lines+markers",
70
70
  line=dict(color=col, width=1.5),
@@ -74,14 +74,18 @@ def _scree_plot(y, y_lab, main):
74
74
  ax_x = axis_num("Index", list(x), [str(i) for i in x])
75
75
  ax_y = axis_num(y_lab, axT2, axis_format(axT2, 2))
76
76
  ax_y.update(showgrid=True,
77
- gridcolor=to_hex(style["grid_col"]),
77
+ gridcolor=as_plotly_color(style["grid_col"]),
78
78
  gridwidth=1, griddash="dot")
79
79
  fig.update_layout(
80
80
  xaxis=ax_x, yaxis=ax_y,
81
81
  shapes=x_grid(list(x)) + plot_border(), template=None,
82
- plot_bgcolor=to_hex(style["panel_fill"]),
83
- paper_bgcolor=to_hex(style["window_fill"]),
82
+ plot_bgcolor=as_plotly_color(style["panel_fill"]),
83
+ paper_bgcolor=as_plotly_color(style["window_fill"]),
84
84
  title=dict(text=main or "", x=0.5, xanchor="center",
85
85
  font=dict(size=round(
86
86
  16 * get_option("main_size", 1)))))
87
87
  return fig
88
+
89
+
90
+ # pdf_file= and png_file= write the figures, as lessR's pdf_file=
91
+ corScree = file_output(corScree)