onekit 2.1.1__tar.gz → 2.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: onekit
3
- Version: 2.1.1
3
+ Version: 2.2.0
4
4
  Summary: All-in-One Python Kit.
5
5
  License: BSD 3-Clause
6
6
  Keywords: onekit
@@ -22,7 +22,7 @@ requires-python = ">=3.11"
22
22
  dependencies = []
23
23
 
24
24
  [tool.poetry]
25
- version = "2.1.1"
25
+ version = "2.2.0"
26
26
 
27
27
  [project.optional-dependencies]
28
28
  base = [
@@ -13,6 +13,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable
13
13
  from mpl_toolkits.mplot3d.axes3d import Axes3D
14
14
 
15
15
  from onekit import numpykit as npk
16
+ from onekit import pythonkit as pk
16
17
 
17
18
  __all__ = (
18
19
  "Config",
@@ -21,6 +22,7 @@ __all__ = (
21
22
  "create_xyz_points",
22
23
  "discrete_cmap",
23
24
  "plot_contour",
25
+ "plot_digitscale",
24
26
  "plot_line",
25
27
  "plot_surface",
26
28
  "plot_xy_points",
@@ -481,6 +483,66 @@ def plot_contour(
481
483
  return ax
482
484
 
483
485
 
486
+ def plot_digitscale(
487
+ x,
488
+ /,
489
+ *,
490
+ cmap_name: str = "YlOrBr_r",
491
+ kws_plot: dict[str, str] | None = None,
492
+ ax=None,
493
+ ) -> Axes:
494
+ """Plot a scaled version of :math:`x` using digitscale.
495
+
496
+ See Also
497
+ --------
498
+ onekit.mathkit.digitscale : Python version
499
+
500
+ Examples
501
+ --------
502
+ >>> from onekit import mathkit as mk
503
+ >>> from onekit import vizkit as vk
504
+ >>> vk.plot_digitscale(tuple(mk.collatz(27))) # doctest: +SKIP
505
+ """
506
+ ax = ax or plt.gca()
507
+
508
+ kwargs_plot = dict(marker=".", color="black")
509
+ kwargs_plot.update(kws_plot or dict())
510
+
511
+ x_values = np.asarray(x)
512
+ x_scaled = npk.digitscale(x_values)
513
+ ax.plot(x_scaled, **kwargs_plot)
514
+ x_limits = ax.get_xlim()
515
+
516
+ y_min = int(np.floor(x_scaled.min()))
517
+ y_max = int(np.ceil(x_scaled.max()))
518
+ y_range = tuple(range(y_min, y_max))
519
+ colors = discrete_cmap(y_max, name=cmap_name, lower_bound=0.2, upper_bound=0.8)
520
+
521
+ for i, y in enumerate(y_range):
522
+ ax.fill_between(x_limits, y, y + 1, color=colors[i], alpha=0.3)
523
+
524
+ ax.set_xlim(x_limits)
525
+ ax.set_yticks(y_range)
526
+
527
+ ax.set_xlabel("index")
528
+ ax.set_ylabel("num_digits(orig_value)")
529
+
530
+ ax.set_title(
531
+ pk.concat_strings(
532
+ ", ",
533
+ f"mean={pk.num_to_str(x_values.mean())}",
534
+ f"median={pk.num_to_str(float(np.median(x_values)))}",
535
+ f"std={pk.num_to_str(x_values.std(ddof=1))}",
536
+ f"min={pk.num_to_str(x_values.min())}",
537
+ f"max={pk.num_to_str(x_values.max())}",
538
+ ),
539
+ size="medium",
540
+ pad=12,
541
+ )
542
+
543
+ return ax
544
+
545
+
484
546
  def plot_line(xy_pts: XyPoints, /, *, kws_plot=None, ax=None) -> Axes:
485
547
  """Plot :math:`y` versus :math:`x` as line.
486
548
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes