py2ls 0.1.8.9__py3-none-any.whl → 0.1.9.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.
py2ls/plot.py CHANGED
@@ -17,7 +17,10 @@ logging.getLogger("fontTools").setLevel(logging.WARNING)
17
17
  def catplot(data, *args, **kwargs):
18
18
  """
19
19
  catplot(data, opt=None, ax=None)
20
-
20
+ The catplot function is designed to provide a flexible way to create various types of
21
+ categorical plots. It supports multiple plot layers such as bars, error bars, scatter
22
+ plots, box plots, violin plots, and lines. Each plot type is handled by its own internal
23
+ function, allowing for separation of concerns and modularity in the design.
21
24
  Args:
22
25
  data (array): data matrix
23
26
  """
@@ -459,255 +462,277 @@ def catplot(data, *args, **kwargs):
459
462
  # custom_order = ['s', 'bx', 'e']
460
463
  # full_order = sort_catplot_layers(custom_order)
461
464
 
462
- # figsets
463
- kw_figsets = kwargs.get("figsets", None)
464
- # check the data type
465
- if isinstance(data, pd.DataFrame):
466
- df = data.copy()
467
- x = kwargs.get("x", None)
468
- y = kwargs.get("y", None)
469
- hue = kwargs.get("hue", None)
470
- data = df2array(data=data, x=x, y=y, hue=hue)
471
- xticklabels = []
472
- if hue is not None:
473
- for i in df[x].unique().tolist():
474
- for j in df[hue].unique().tolist():
475
- xticklabels.append(i + "-" + j)
476
- x_len = len(df[x].unique().tolist())
477
- hue_len = len(df[hue].unique().tolist())
478
- xticks = generate_xticks_with_gap(x_len, hue_len)
479
- default_x_width = 0.85
480
- legend_hue = df[hue].unique().tolist()
481
- default_colors = get_color(hue_len)
465
+ col = kwargs.get("col", None)
466
+ if not col:
467
+ # figsets
468
+ kw_figsets = kwargs.get("figsets", None)
469
+ # check the data type
470
+ if isinstance(data, pd.DataFrame):
471
+ df = data.copy()
472
+ x = kwargs.get("x", None)
473
+ y = kwargs.get("y", None)
474
+ hue = kwargs.get("hue", None)
475
+ data = df2array(data=data, x=x, y=y, hue=hue)
476
+ xticklabels = []
477
+ if hue is not None:
478
+ for i in df[x].unique().tolist():
479
+ for j in df[hue].unique().tolist():
480
+ xticklabels.append(i + "-" + j)
481
+ x_len = len(df[x].unique().tolist())
482
+ hue_len = len(df[hue].unique().tolist())
483
+ xticks = generate_xticks_with_gap(x_len, hue_len)
484
+ default_x_width = 0.85
485
+ legend_hue = df[hue].unique().tolist()
486
+ default_colors = get_color(hue_len)
487
+ else:
488
+ for i in df[x].unique().tolist():
489
+ xticklabels.append(i)
490
+ xticks = np.arange(1, len(xticklabels) + 1).tolist()
491
+ legend_hue = xticklabels
492
+ default_colors = get_color(len(xticklabels))
493
+ default_x_width = 0.5
494
+
495
+ # when the xticklabels are too long, rotate the labels a bit
496
+
497
+ xangle = 30 if max([len(i) for i in xticklabels]) > 5 else 0
498
+ if kw_figsets is not None:
499
+ kw_figsets = {
500
+ "ylabel": y,
501
+ # "xlabel": x,
502
+ "xticks": xticks,
503
+ "xticklabels": xticklabels,
504
+ "xangle": xangle,
505
+ **kw_figsets,
506
+ }
507
+ else:
508
+ kw_figsets = {
509
+ "ylabel": y,
510
+ # "xlabel": x,
511
+ "xticks": xticks,
512
+ "xticklabels": xticklabels,
513
+ "xangle": xangle,
514
+ }
482
515
  else:
483
- for i in df[x].unique().tolist():
484
- xticklabels.append(i)
485
- xticks = np.arange(1, len(xticklabels) + 1).tolist()
486
- legend_hue = xticklabels
487
- default_colors = get_color(len(xticklabels))
516
+ xticks = np.arange(1, data.shape[1] + 1).tolist()
488
517
  default_x_width = 0.5
518
+ default_colors = get_color(len(xticks))
519
+ legend_hue = None
520
+ xangle = 0
521
+
522
+ # full_order
523
+ opt = kwargs.get("opt", {})
524
+ ax = kwargs.get("ax", None)
525
+ if "ax" not in locals() or ax is None:
526
+ ax = plt.gca()
527
+ opt.setdefault("c", default_colors)
528
+ # if len(opt["c"]) < data.shape[1]:
529
+ # additional_colors = plt.cm.winter(
530
+ # np.linspace(0, 1, data.shape[1] - len(opt["c"]))
531
+ # )
532
+ # opt["c"] = np.vstack([opt["c"], additional_colors[:, :3]])
533
+
534
+ opt.setdefault("loc", {})
535
+ opt["loc"].setdefault("go", 0)
536
+ opt["loc"].setdefault("xloc", xticks)
537
+
538
+ # export setting
539
+ opt.setdefault("export", {})
540
+ opt["export"].setdefault("path", None)
541
+ print(opt["export"])
542
+
543
+ # opt.setdefault('layer', {})
544
+ opt.setdefault("layer", ["b", "bx", "e", "v", "s", "l"])
545
+
546
+ opt.setdefault("b", {})
547
+ opt["b"].setdefault("go", 1)
548
+ opt["b"].setdefault("loc", "c")
549
+ opt["b"].setdefault("FaceColor", opt["c"])
550
+ opt["b"].setdefault("FaceAlpha", 1)
551
+ opt["b"].setdefault("EdgeColor", "k")
552
+ opt["b"].setdefault("EdgeAlpha", 1)
553
+ opt["b"].setdefault("LineStyle", "-")
554
+ opt["b"].setdefault("LineWidth", 0.8)
555
+ opt["b"].setdefault("x_width", default_x_width)
556
+ opt["b"].setdefault("ShowBaseLine", "off")
557
+ opt["b"].setdefault("hatch", None)
558
+
559
+ opt.setdefault("e", {})
560
+ opt["e"].setdefault("go", 1)
561
+ opt["e"].setdefault("loc", "l")
562
+ opt["e"].setdefault("LineWidth", 1)
563
+ opt["e"].setdefault("CapLineWidth", 1)
564
+ opt["e"].setdefault("CapSize", 2)
565
+ opt["e"].setdefault("Marker", "none")
566
+ opt["e"].setdefault("LineStyle", "none")
567
+ opt["e"].setdefault("LineColor", "k")
568
+ opt["e"].setdefault("LineJoin", "round")
569
+ opt["e"].setdefault("MarkerSize", "auto")
570
+ opt["e"].setdefault("FaceColor", opt["c"])
571
+ opt["e"].setdefault("MarkerEdgeColor", "none")
572
+ opt["e"].setdefault("Visible", True)
573
+ opt["e"].setdefault("Orientation", "vertical")
574
+ opt["e"].setdefault("error", "sem")
575
+ opt["e"].setdefault("x_width", opt["b"]["x_width"] / 5)
576
+ opt["e"].setdefault("cap_dir", "b")
577
+
578
+ opt.setdefault("s", {})
579
+ opt["s"].setdefault("go", 1)
580
+ opt["s"].setdefault("loc", "r")
581
+ opt["s"].setdefault("FaceColor", "w")
582
+ opt["s"].setdefault("cmap", None)
583
+ opt["s"].setdefault("FaceAlpha", 1)
584
+ opt["s"].setdefault("x_width", opt["b"]["x_width"] / 5)
585
+ opt["s"].setdefault("Marker", "o")
586
+ opt["s"].setdefault("MarkerSize", 15)
587
+ opt["s"].setdefault("LineWidth", 0.8)
588
+ opt["s"].setdefault("MarkerEdgeColor", "k")
589
+
590
+ opt.setdefault("l", {})
591
+ opt["l"].setdefault("go", 1)
592
+ opt["l"].setdefault("LineStyle", "-")
593
+ opt["l"].setdefault("LineColor", "k")
594
+ opt["l"].setdefault("LineWidth", 0.5)
595
+ opt["l"].setdefault("LineAlpha", 0.5)
596
+
597
+ opt.setdefault("bx", {})
598
+ opt["bx"].setdefault("go", 0)
599
+ opt["bx"].setdefault("loc", "r")
600
+ opt["bx"].setdefault("FaceColor", opt["c"])
601
+ opt["bx"].setdefault("EdgeColor", "k")
602
+ opt["bx"].setdefault("FaceAlpha", 0.85)
603
+ opt["bx"].setdefault("EdgeAlpha", 1)
604
+ opt["bx"].setdefault("LineStyle", "-")
605
+ opt["bx"].setdefault("x_width", 0.2)
606
+ opt["bx"].setdefault("ShowBaseLine", "off")
607
+ opt["bx"].setdefault("Notch", False)
608
+ opt["bx"].setdefault("Outliers", "on")
609
+ opt["bx"].setdefault("OutlierMarker", "+")
610
+ opt["bx"].setdefault("OutlierColor", "r")
611
+ opt["bx"].setdefault("OutlierSize", 6)
612
+ # opt['bx'].setdefault('PlotStyle', 'traditional')
613
+ # opt['bx'].setdefault('FactorDirection', 'auto')
614
+ opt["bx"].setdefault("Whisker", 0.5)
615
+ opt["bx"].setdefault("Orientation", "vertical")
616
+ opt["bx"].setdefault("BoxLineWidth", 0.5)
617
+ opt["bx"].setdefault("FaceColor", "k")
618
+ opt["bx"].setdefault("WhiskerLineStyle", "-")
619
+ opt["bx"].setdefault("WhiskerLineColor", "k")
620
+ opt["bx"].setdefault("WhiskerLineWidth", 0.5)
621
+ opt["bx"].setdefault("Caps", True)
622
+ opt["bx"].setdefault("CapLineColor", "k")
623
+ opt["bx"].setdefault("CapLineWidth", 0.5)
624
+ opt["bx"].setdefault("CapSize", 0.2)
625
+ opt["bx"].setdefault("MedianLine", True)
626
+ opt["bx"].setdefault("MedianLineStyle", "-")
627
+ opt["bx"].setdefault("MedianStyle", "line")
628
+ opt["bx"].setdefault("MedianLineColor", "k")
629
+ opt["bx"].setdefault("MedianLineWidth", 2)
630
+ opt["bx"].setdefault("MedianLineTop", False)
631
+ opt["bx"].setdefault("MeanLine", False)
632
+ opt["bx"].setdefault("showmeans", opt["bx"]["MeanLine"])
633
+ opt["bx"].setdefault("MeanLineStyle", "-")
634
+ opt["bx"].setdefault("MeanLineColor", "w")
635
+ opt["bx"].setdefault("MeanLineWidth", 2)
636
+
637
+ # Violin plot options
638
+ opt.setdefault("v", {})
639
+ opt["v"].setdefault("go", 0)
640
+ opt["v"].setdefault("x_width", 0.3)
641
+ opt["v"].setdefault("loc", "r")
642
+ opt["v"].setdefault("EdgeColor", "none")
643
+ opt["v"].setdefault("FaceColor", opt["c"])
644
+ opt["v"].setdefault("FaceAlpha", 0.3)
645
+ opt["v"].setdefault("BandWidth", "scott")
646
+ opt["v"].setdefault("Function", "pdf")
647
+ opt["v"].setdefault("Kernel", "gau")
648
+ opt["v"].setdefault("NumPoints", 500)
649
+ opt["v"].setdefault("BoundaryCorrection", "reflection")
650
+
651
+ data_m = np.nanmean(data, axis=0)
652
+ nr, nc = data.shape
653
+
654
+ for key in kwargs.keys():
655
+ if key in opt:
656
+ if isinstance(kwargs[key], dict):
657
+ opt[key].update(kwargs[key])
658
+ else:
659
+ opt[key] = kwargs[key]
660
+ if isinstance(opt["loc"]["xloc"], list):
661
+ xloc = np.array(opt["loc"]["xloc"])
662
+ else:
663
+ xloc = opt["loc"]["xloc"]
664
+ layers = sort_catplot_layers(opt["layer"])
665
+
666
+ label_which = kwargs.get("label_which", "barplot")
667
+ if "b" in label_which:
668
+ legend_which = "b"
669
+ elif "s" in label_which:
670
+ legend_which = "s"
671
+ elif "bx" in label_which:
672
+ legend_which = "bx"
673
+ elif "e" in label_which:
674
+ legend_which = "e"
675
+ elif "v" in label_which:
676
+ legend_which = "v"
677
+ else:
678
+ legend_which = None
489
679
 
490
- # when the xticklabels are too long, rotate the labels a bit
680
+ for layer in layers:
681
+ if layer == "b" and opt["b"]["go"]:
682
+ if legend_which == "b":
683
+ plot_bars(data, data_m, opt["b"], xloc, ax, label=legend_hue)
684
+ else:
685
+ plot_bars(data, data_m, opt["b"], xloc, ax, label=None)
686
+ elif layer == "e" and opt["e"]["go"]:
687
+ if legend_which == "e":
688
+ plot_errors(data, data_m, opt["e"], xloc, ax, label=legend_hue)
689
+ else:
690
+ plot_errors(data, data_m, opt["e"], xloc, ax, label=None)
691
+ elif layer == "s" and opt["s"]["go"]:
692
+ if legend_which == "s":
693
+ plot_scatter(data, opt["s"], xloc, ax, label=legend_hue)
694
+ else:
695
+ plot_scatter(data, opt["s"], xloc, ax, label=None)
696
+ elif layer == "bx" and opt["bx"]["go"]:
697
+ if legend_which == "bx":
698
+ plot_boxplot(data, opt["bx"], xloc, ax, label=legend_hue)
699
+ else:
700
+ plot_boxplot(data, opt["bx"], xloc, ax, label=None)
701
+ elif layer == "v" and opt["v"]["go"]:
702
+ if legend_which == "v":
703
+ plot_violin(data, opt["v"], xloc, ax, label=legend_hue)
704
+ else:
705
+ plot_violin(data, opt["v"], xloc, ax, label=None)
706
+ elif all([layer == "l", opt["l"]["go"], opt["s"]["go"]]):
707
+ plot_lines(data, opt["l"], opt["s"], ax)
491
708
 
492
- xangle = 30 if max([len(i) for i in xticklabels]) > 5 else 0
493
709
  if kw_figsets is not None:
494
- kw_figsets = {
495
- "ylabel": y,
496
- "xlabel": x,
497
- "xticks": xticks,
498
- "xticklabels": xticklabels,
499
- "xangle": xangle,
500
- **kw_figsets,
501
- }
502
- else:
503
- kw_figsets = {
504
- "ylabel": y,
505
- "xlabel": x,
506
- "xticks": xticks,
507
- "xticklabels": xticklabels,
508
- "xangle": xangle,
509
- }
710
+ figsets(ax=ax, **kw_figsets)
711
+ show_legend = kwargs.get("show_legend", True)
712
+ if show_legend:
713
+ ax.legend()
714
+ export_style = kwargs.get("export_style", None)
715
+ if export_style:
716
+ fsave(export_style, opt)
717
+ return ax, opt
510
718
  else:
511
- xticks = np.arange(1, data.shape[1] + 1).tolist()
512
- default_x_width = 0.5
513
- xangle = 0
514
-
515
- # full_order
516
- opt = kwargs.get("opt", {})
517
- ax = kwargs.get("ax", None)
518
- if "ax" not in locals() or ax is None:
519
- ax = plt.gca()
520
- opt.setdefault("c", default_colors)
521
- # if len(opt["c"]) < data.shape[1]:
522
- # additional_colors = plt.cm.winter(
523
- # np.linspace(0, 1, data.shape[1] - len(opt["c"]))
524
- # )
525
- # opt["c"] = np.vstack([opt["c"], additional_colors[:, :3]])
526
-
527
- opt.setdefault("loc", {})
528
- opt["loc"].setdefault("go", 0)
529
- opt["loc"].setdefault("xloc", xticks)
530
-
531
- # export setting
532
- opt.setdefault("export", {})
533
- opt["export"].setdefault("path", None)
534
- print(opt["export"])
535
-
536
- # opt.setdefault('layer', {})
537
- opt.setdefault("layer", ["b", "bx", "e", "v", "s", "l"])
538
-
539
- opt.setdefault("b", {})
540
- opt["b"].setdefault("go", 1)
541
- opt["b"].setdefault("loc", "c")
542
- opt["b"].setdefault("FaceColor", opt["c"])
543
- opt["b"].setdefault("FaceAlpha", 1)
544
- opt["b"].setdefault("EdgeColor", "k")
545
- opt["b"].setdefault("EdgeAlpha", 1)
546
- opt["b"].setdefault("LineStyle", "-")
547
- opt["b"].setdefault("LineWidth", 0.8)
548
- opt["b"].setdefault("x_width", default_x_width)
549
- opt["b"].setdefault("ShowBaseLine", "off")
550
- opt["b"].setdefault("hatch", None)
551
-
552
- opt.setdefault("e", {})
553
- opt["e"].setdefault("go", 1)
554
- opt["e"].setdefault("loc", "l")
555
- opt["e"].setdefault("LineWidth", 1)
556
- opt["e"].setdefault("CapLineWidth", 1)
557
- opt["e"].setdefault("CapSize", 2)
558
- opt["e"].setdefault("Marker", "none")
559
- opt["e"].setdefault("LineStyle", "none")
560
- opt["e"].setdefault("LineColor", "k")
561
- opt["e"].setdefault("LineJoin", "round")
562
- opt["e"].setdefault("MarkerSize", "auto")
563
- opt["e"].setdefault("FaceColor", opt["c"])
564
- opt["e"].setdefault("MarkerEdgeColor", "none")
565
- opt["e"].setdefault("Visible", True)
566
- opt["e"].setdefault("Orientation", "vertical")
567
- opt["e"].setdefault("error", "sem")
568
- opt["e"].setdefault("x_width", opt["b"]["x_width"] / 5)
569
- opt["e"].setdefault("cap_dir", "b")
570
-
571
- opt.setdefault("s", {})
572
- opt["s"].setdefault("go", 1)
573
- opt["s"].setdefault("loc", "r")
574
- opt["s"].setdefault("FaceColor", "w")
575
- opt["s"].setdefault("cmap", None)
576
- opt["s"].setdefault("FaceAlpha", 1)
577
- opt["s"].setdefault("x_width", opt["b"]["x_width"] / 5)
578
- opt["s"].setdefault("Marker", "o")
579
- opt["s"].setdefault("MarkerSize", 15)
580
- opt["s"].setdefault("LineWidth", 0.8)
581
- opt["s"].setdefault("MarkerEdgeColor", "k")
582
-
583
- opt.setdefault("l", {})
584
- opt["l"].setdefault("go", 1)
585
- opt["l"].setdefault("LineStyle", "-")
586
- opt["l"].setdefault("LineColor", "k")
587
- opt["l"].setdefault("LineWidth", 0.5)
588
- opt["l"].setdefault("LineAlpha", 0.5)
589
-
590
- opt.setdefault("bx", {})
591
- opt["bx"].setdefault("go", 0)
592
- opt["bx"].setdefault("loc", "r")
593
- opt["bx"].setdefault("FaceColor", opt["c"])
594
- opt["bx"].setdefault("EdgeColor", "k")
595
- opt["bx"].setdefault("FaceAlpha", 0.85)
596
- opt["bx"].setdefault("EdgeAlpha", 1)
597
- opt["bx"].setdefault("LineStyle", "-")
598
- opt["bx"].setdefault("x_width", 0.2)
599
- opt["bx"].setdefault("ShowBaseLine", "off")
600
- opt["bx"].setdefault("Notch", False)
601
- opt["bx"].setdefault("Outliers", "on")
602
- opt["bx"].setdefault("OutlierMarker", "+")
603
- opt["bx"].setdefault("OutlierColor", "r")
604
- opt["bx"].setdefault("OutlierSize", 6)
605
- # opt['bx'].setdefault('PlotStyle', 'traditional')
606
- # opt['bx'].setdefault('FactorDirection', 'auto')
607
- opt["bx"].setdefault("Whisker", 0.5)
608
- opt["bx"].setdefault("Orientation", "vertical")
609
- opt["bx"].setdefault("BoxLineWidth", 0.5)
610
- opt["bx"].setdefault("FaceColor", "k")
611
- opt["bx"].setdefault("WhiskerLineStyle", "-")
612
- opt["bx"].setdefault("WhiskerLineColor", "k")
613
- opt["bx"].setdefault("WhiskerLineWidth", 0.5)
614
- opt["bx"].setdefault("Caps", True)
615
- opt["bx"].setdefault("CapLineColor", "k")
616
- opt["bx"].setdefault("CapLineWidth", 0.5)
617
- opt["bx"].setdefault("CapSize", 0.2)
618
- opt["bx"].setdefault("MedianLine", True)
619
- opt["bx"].setdefault("MedianLineStyle", "-")
620
- opt["bx"].setdefault("MedianStyle", "line")
621
- opt["bx"].setdefault("MedianLineColor", "k")
622
- opt["bx"].setdefault("MedianLineWidth", 2)
623
- opt["bx"].setdefault("MedianLineTop", False)
624
- opt["bx"].setdefault("MeanLine", False)
625
- opt["bx"].setdefault("showmeans", opt["bx"]["MeanLine"])
626
- opt["bx"].setdefault("MeanLineStyle", "-")
627
- opt["bx"].setdefault("MeanLineColor", "w")
628
- opt["bx"].setdefault("MeanLineWidth", 2)
629
-
630
- # Violin plot options
631
- opt.setdefault("v", {})
632
- opt["v"].setdefault("go", 0)
633
- opt["v"].setdefault("x_width", 0.3)
634
- opt["v"].setdefault("loc", "r")
635
- opt["v"].setdefault("EdgeColor", "none")
636
- opt["v"].setdefault("FaceColor", opt["c"])
637
- opt["v"].setdefault("FaceAlpha", 0.3)
638
- opt["v"].setdefault("BandWidth", "scott")
639
- opt["v"].setdefault("Function", "pdf")
640
- opt["v"].setdefault("Kernel", "gau")
641
- opt["v"].setdefault("NumPoints", 500)
642
- opt["v"].setdefault("BoundaryCorrection", "reflection")
643
-
644
- data_m = np.nanmean(data, axis=0)
645
- nr, nc = data.shape
646
-
647
- for key in kwargs.keys():
648
- if key in opt:
649
- if isinstance(kwargs[key], dict):
650
- opt[key].update(kwargs[key])
651
- else:
652
- opt[key] = kwargs[key]
653
- if isinstance(opt["loc"]["xloc"], list):
654
- xloc = np.array(opt["loc"]["xloc"])
655
- else:
656
- xloc = opt["loc"]["xloc"]
657
- layers = sort_catplot_layers(opt["layer"])
658
-
659
- label_which = kwargs.get("label_which", "barplot")
660
- if "b" in label_which:
661
- legend_which = "b"
662
- elif "s" in label_which:
663
- legend_which = "s"
664
- elif "bx" in label_which:
665
- legend_which = "bx"
666
- elif "e" in label_which:
667
- legend_which = "e"
668
- elif "v" in label_which:
669
- legend_which = "v"
670
- else:
671
- legend_which = None
672
-
673
- for layer in layers:
674
- if layer == "b" and opt["b"]["go"]:
675
- if legend_which == "b":
676
- plot_bars(data, data_m, opt["b"], xloc, ax, label=legend_hue)
677
- else:
678
- plot_bars(data, data_m, opt["b"], xloc, ax, label=None)
679
- elif layer == "e" and opt["e"]["go"]:
680
- if legend_which == "e":
681
- plot_errors(data, data_m, opt["e"], xloc, ax, label=legend_hue)
682
- else:
683
- plot_errors(data, data_m, opt["e"], xloc, ax, label=None)
684
- elif layer == "s" and opt["s"]["go"]:
685
- if legend_which == "s":
686
- plot_scatter(data, opt["s"], xloc, ax, label=legend_hue)
687
- else:
688
- plot_scatter(data, opt["s"], xloc, ax, label=None)
689
- elif layer == "bx" and opt["bx"]["go"]:
690
- if legend_which == "bx":
691
- plot_boxplot(data, opt["bx"], xloc, ax, label=legend_hue)
692
- else:
693
- plot_boxplot(data, opt["bx"], xloc, ax, label=None)
694
- elif layer == "v" and opt["v"]["go"]:
695
- if legend_which == "v":
696
- plot_violin(data, opt["v"], xloc, ax, label=legend_hue)
697
- else:
698
- plot_violin(data, opt["v"], xloc, ax, label=None)
699
- elif all([layer == "l", opt["l"]["go"], opt["s"]["go"]]):
700
- plot_lines(data, opt["l"], opt["s"], ax)
701
-
702
- if kw_figsets is not None:
703
- figsets(ax=ax, **kw_figsets)
704
- show_legend = kwargs.get("show_legend", True)
705
- if show_legend:
706
- ax.legend()
707
- export_style = kwargs.get("export_style", None)
708
- if export_style:
709
- fsave(export_style, opt)
710
- return ax, opt
719
+ col_names = data[col].unique().tolist()
720
+ nrow, ncol = kwargs.get("subplots", [len(col_names), 1])
721
+ figsize = kwargs.get("figsize", [3 * ncol, 3 * nrow])
722
+ fig, axs = plt.subplots(nrow, ncol, figsize=figsize, squeeze=False)
723
+ axs = axs.flatten()
724
+ key2rm = ["data", "ax", "col", "subplots"]
725
+ for k2rm in key2rm:
726
+ if k2rm in kwargs:
727
+ del kwargs[k2rm]
728
+ for i, ax in enumerate(axs):
729
+ # ax = axs[i][0] if len(col_names) > 1 else axs[0]
730
+ if i < len(col_names):
731
+ df_sub = data.loc[data[col] == col_names[i]]
732
+ catplot(ax=ax, data=df_sub, **kwargs)
733
+ ax.set_title(col_names[i])
734
+ print(f"Axis layout shape: {axs.shape}")
735
+ return axs
711
736
 
712
737
 
713
738
  def get_cmap():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.8.9
3
+ Version: 0.1.9.0
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -136,12 +136,12 @@ py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,
136
136
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
137
137
  py2ls/ips.py,sha256=N7MdOCgJXDQu73YkJQTtDN3RSntzXX7V0MOJ1NYBLEk,100572
138
138
  py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
139
- py2ls/plot.py,sha256=9_vyFNoPX4c8b0AS3lyFu18QKec5je3f0G8T7di9K9o,63197
139
+ py2ls/plot.py,sha256=1hwNRxvI-oHwyvs6coupyl_xR6c3aLeIcgSnenl-i4Y,65406
140
140
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
141
141
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
142
142
  py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
143
143
  py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
144
144
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
145
- py2ls-0.1.8.9.dist-info/METADATA,sha256=7-nSwoDVg7Yf3lZ8pqIZ6b-voypM-2p9vwDWoSLqGFs,20017
146
- py2ls-0.1.8.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.8.9.dist-info/RECORD,,
145
+ py2ls-0.1.9.0.dist-info/METADATA,sha256=vmri4oGNRRS-eJxRHjWOd2pOd2xq3iyOUkgX9LJsVTA,20017
146
+ py2ls-0.1.9.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
+ py2ls-0.1.9.0.dist-info/RECORD,,