pandas-plots 0.11.23__py3-none-any.whl → 0.11.24__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.
- pandas_plots/pls.py +69 -19
- {pandas_plots-0.11.23.dist-info → pandas_plots-0.11.24.dist-info}/METADATA +1 -1
- pandas_plots-0.11.24.dist-info/RECORD +10 -0
- {pandas_plots-0.11.23.dist-info → pandas_plots-0.11.24.dist-info}/WHEEL +1 -1
- pandas_plots-0.11.23.dist-info/RECORD +0 -10
- {pandas_plots-0.11.23.dist-info → pandas_plots-0.11.24.dist-info}/LICENSE +0 -0
- {pandas_plots-0.11.23.dist-info → pandas_plots-0.11.24.dist-info}/top_level.txt +0 -0
pandas_plots/pls.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from pathlib import Path
|
1
2
|
import warnings
|
2
3
|
|
3
4
|
warnings.filterwarnings("ignore")
|
@@ -22,7 +23,8 @@ def plot_quadrants(
|
|
22
23
|
df: pd.DataFrame,
|
23
24
|
title: str = None,
|
24
25
|
caption: str = None,
|
25
|
-
|
26
|
+
png_path: Path | str = None,
|
27
|
+
) -> object:
|
26
28
|
"""
|
27
29
|
Plot a heatmap for the given dataframe, with options for title and caption.
|
28
30
|
|
@@ -35,6 +37,7 @@ def plot_quadrants(
|
|
35
37
|
df columns must contain 2 values
|
36
38
|
title (str, optional): The title for the heatmap to override the default.
|
37
39
|
caption (str, optional): The caption for the heatmap. Defaults to None.
|
40
|
+
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
38
41
|
|
39
42
|
Returns:
|
40
43
|
q1, q2, q3, q4, n: The values for each quadrant and the total count.
|
@@ -93,6 +96,10 @@ def plot_quadrants(
|
|
93
96
|
q3 = heat_wide_out.iloc[0, 0]
|
94
97
|
q4 = heat_wide_out.iloc[0, 1]
|
95
98
|
|
99
|
+
# * save to png if path is provided
|
100
|
+
if png_path is not None:
|
101
|
+
plt.savefig(Path(png_path).as_posix(), format='png')
|
102
|
+
|
96
103
|
return q1, q2, q3, q4, n
|
97
104
|
# * plotly express is not used for the heatmap, although it does not need the derived wide format.
|
98
105
|
# * but theres no option to alter inner values in the heatmap
|
@@ -115,7 +122,8 @@ def plot_stacked_bars(
|
|
115
122
|
sort_values: bool = False,
|
116
123
|
show_total: bool = False,
|
117
124
|
precision: int = 0,
|
118
|
-
|
125
|
+
png_path: Path | str = None,
|
126
|
+
) -> object:
|
119
127
|
"""
|
120
128
|
Generates a stacked bar plot using the provided DataFrame.
|
121
129
|
df *must* comprise the columns (order matters):
|
@@ -140,9 +148,10 @@ def plot_stacked_bars(
|
|
140
148
|
- sort_values: bool = False - Sort axis by index (default) or values
|
141
149
|
- show_total: bool = False - Whether to show the total value
|
142
150
|
- precision: int = 0 - The number of decimal places to round to
|
151
|
+
- png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
143
152
|
|
144
153
|
Returns:
|
145
|
-
|
154
|
+
plot object
|
146
155
|
"""
|
147
156
|
BAR_LENGTH_MULTIPLIER = 1.05
|
148
157
|
|
@@ -322,7 +331,12 @@ def plot_stacked_bars(
|
|
322
331
|
_fig.update_layout(yaxis={"categoryorder": "category descending"})
|
323
332
|
|
324
333
|
_fig.show(renderer)
|
325
|
-
|
334
|
+
|
335
|
+
# * save to png if path is provided
|
336
|
+
if png_path is not None:
|
337
|
+
_fig.write_image(Path(png_path).as_posix())
|
338
|
+
|
339
|
+
return _fig
|
326
340
|
|
327
341
|
|
328
342
|
def plot_bars(
|
@@ -340,7 +354,8 @@ def plot_bars(
|
|
340
354
|
use_ci: bool = False,
|
341
355
|
precision: int = 0,
|
342
356
|
renderer: Literal["png", "svg", None] = "png",
|
343
|
-
|
357
|
+
png_path: Path | str = None,
|
358
|
+
) -> object:
|
344
359
|
"""
|
345
360
|
A function to plot a bar chart based on a *categorical* column (must be string or bool) and a numerical value.
|
346
361
|
Accepts:
|
@@ -366,9 +381,10 @@ def plot_bars(
|
|
366
381
|
- enforces dropna=True
|
367
382
|
- precision: An integer indicating the number of decimal places to round the values to. Default is 0.
|
368
383
|
- renderer: A string indicating the renderer to use for displaying the chart. It can be "png", "svg", or None. Default is "png".
|
384
|
+
- png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
369
385
|
|
370
386
|
Returns:
|
371
|
-
-
|
387
|
+
- plot object
|
372
388
|
"""
|
373
389
|
# * if series, apply value_counts, deselect use_ci
|
374
390
|
if isinstance(df_in, pd.Series):
|
@@ -568,7 +584,12 @@ def plot_bars(
|
|
568
584
|
textposition="outside" if not use_ci else "auto", error_y=dict(thickness=5)
|
569
585
|
)
|
570
586
|
_fig.show(renderer)
|
571
|
-
|
587
|
+
|
588
|
+
# * save to png if path is provided
|
589
|
+
if png_path is not None:
|
590
|
+
_fig.write_image(Path(png_path).as_posix())
|
591
|
+
|
592
|
+
return _fig
|
572
593
|
|
573
594
|
|
574
595
|
def plot_histogram(
|
@@ -586,7 +607,8 @@ def plot_histogram(
|
|
586
607
|
renderer: Literal["png", "svg", None] = "png",
|
587
608
|
caption: str = None,
|
588
609
|
title: str = None,
|
589
|
-
|
610
|
+
png_path: Path | str = None,
|
611
|
+
) -> object:
|
590
612
|
"""
|
591
613
|
A function to plot a histogram based on *numeric* columns in a DataFrame.
|
592
614
|
Accepts:
|
@@ -606,9 +628,11 @@ def plot_histogram(
|
|
606
628
|
renderer (Literal["png", "svg", None]): The renderer for displaying the plot. Default is "png".
|
607
629
|
caption (str): The caption for the plot. Default is None.
|
608
630
|
title (str): The title of the plot. Default is None.
|
631
|
+
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
632
|
+
|
609
633
|
|
610
634
|
Returns:
|
611
|
-
|
635
|
+
plot object
|
612
636
|
"""
|
613
637
|
|
614
638
|
# * convert to df if series
|
@@ -657,7 +681,12 @@ def plot_histogram(
|
|
657
681
|
)
|
658
682
|
|
659
683
|
fig.show(renderer)
|
660
|
-
|
684
|
+
|
685
|
+
# * save to png if path is provided
|
686
|
+
if png_path is not None:
|
687
|
+
fig.write_image(Path(png_path).as_posix())
|
688
|
+
|
689
|
+
return fig
|
661
690
|
|
662
691
|
|
663
692
|
def plot_joint(
|
@@ -668,7 +697,8 @@ def plot_joint(
|
|
668
697
|
dropna: bool = False,
|
669
698
|
caption: str = "",
|
670
699
|
title: str = "",
|
671
|
-
|
700
|
+
png_path: Path | str = None,
|
701
|
+
) -> object:
|
672
702
|
"""
|
673
703
|
Generate a seaborn joint plot for *two numeric* columns of a given DataFrame.
|
674
704
|
|
@@ -680,9 +710,10 @@ def plot_joint(
|
|
680
710
|
- dropna: Whether to drop NA values before plotting (default is False).
|
681
711
|
- caption: A caption for the plot.
|
682
712
|
- title: The title of the plot.
|
713
|
+
- png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
683
714
|
|
684
715
|
Returns:
|
685
|
-
|
716
|
+
plot object
|
686
717
|
"""
|
687
718
|
|
688
719
|
if df.shape[1] != 2:
|
@@ -750,7 +781,11 @@ def plot_joint(
|
|
750
781
|
# dropna=dropna,
|
751
782
|
# cmap=_cmap,
|
752
783
|
# )
|
753
|
-
|
784
|
+
# * save to png if path is provided
|
785
|
+
if png_path is not None:
|
786
|
+
fig.savefig(Path(png_path).as_posix())
|
787
|
+
|
788
|
+
return fig
|
754
789
|
|
755
790
|
|
756
791
|
def plot_box(
|
@@ -766,7 +801,8 @@ def plot_box(
|
|
766
801
|
violin: bool = False,
|
767
802
|
x_min: float = None,
|
768
803
|
x_max: float = None,
|
769
|
-
|
804
|
+
png_path: Path | str = None,
|
805
|
+
) -> object:
|
770
806
|
"""
|
771
807
|
Plots a horizontal box plot for the given pandas Series.
|
772
808
|
|
@@ -781,9 +817,10 @@ def plot_box(
|
|
781
817
|
x_min: The minimum value for the x-axis scale (max and min must be set)
|
782
818
|
x_max: The maximum value for the x-axis scale (max and min must be set)
|
783
819
|
summary: Whether to add a summary table to the plot
|
820
|
+
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
784
821
|
|
785
822
|
Returns:
|
786
|
-
|
823
|
+
plot object
|
787
824
|
"""
|
788
825
|
ser = to_series(ser)
|
789
826
|
if ser is None:
|
@@ -896,9 +933,15 @@ def plot_box(
|
|
896
933
|
)
|
897
934
|
|
898
935
|
fig.show("png")
|
936
|
+
|
899
937
|
if summary:
|
900
938
|
print_summary(ser)
|
901
|
-
|
939
|
+
|
940
|
+
# * save to png if path is provided
|
941
|
+
if png_path is not None:
|
942
|
+
fig.write_image(Path(png_path).as_posix())
|
943
|
+
|
944
|
+
return fig
|
902
945
|
|
903
946
|
|
904
947
|
def plot_boxes(
|
@@ -911,7 +954,8 @@ def plot_boxes(
|
|
911
954
|
annotations: bool = True,
|
912
955
|
summary: bool = True,
|
913
956
|
title: str = None,
|
914
|
-
|
957
|
+
png_path: Path | str = None,
|
958
|
+
) -> object:
|
915
959
|
"""
|
916
960
|
[Experimental] Plot vertical boxes for each unique item in the DataFrame and add annotations for statistics.
|
917
961
|
|
@@ -924,9 +968,10 @@ def plot_boxes(
|
|
924
968
|
width (int): The width of the plot.
|
925
969
|
annotations (bool): Whether to add annotations to the plot.
|
926
970
|
summary (bool): Whether to add a summary to the plot.
|
971
|
+
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
927
972
|
|
928
973
|
Returns:
|
929
|
-
|
974
|
+
plot object
|
930
975
|
"""
|
931
976
|
|
932
977
|
if (
|
@@ -1039,7 +1084,12 @@ def plot_boxes(
|
|
1039
1084
|
fig.show("png")
|
1040
1085
|
if summary:
|
1041
1086
|
print_summary(df)
|
1042
|
-
|
1087
|
+
|
1088
|
+
# * save to png if path is provided
|
1089
|
+
if png_path is not None:
|
1090
|
+
fig.write_image(Path(png_path).as_posix())
|
1091
|
+
|
1092
|
+
return fig
|
1043
1093
|
|
1044
1094
|
|
1045
1095
|
# def plot_ci_bars_DEPR(df: pd.DataFrame, dropna: bool = True, precision: int = 2) -> None:
|
@@ -0,0 +1,10 @@
|
|
1
|
+
pandas_plots/hlp.py,sha256=N6NrbFagVMMX-ZnV0rIBEz82SeSoOkksfMcCap55W7E,16588
|
2
|
+
pandas_plots/pii.py,sha256=2WKE-W9s285jPdsTqCgt1uxuW4lj1PYCVOYB2fYDNwQ,2195
|
3
|
+
pandas_plots/pls.py,sha256=U-tjh0DnYQYg-n02hh_HyvObMerkGCBP8tirKFIEEn4,37376
|
4
|
+
pandas_plots/tbl.py,sha256=A1SqvssDA4ofI_WJ-sdWIb9Bo5X-sELD8pley22Y4X4,28380
|
5
|
+
pandas_plots/ven.py,sha256=2x3ACo2vSfO3q6fv-UdDQ0h1SJyt8WChBGgE5SDCdCk,11673
|
6
|
+
pandas_plots-0.11.24.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
|
7
|
+
pandas_plots-0.11.24.dist-info/METADATA,sha256=rapR9ocNOI-6U2PyTtDOTJu2EpZaGxXlywAtOBVHdoA,7220
|
8
|
+
pandas_plots-0.11.24.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
9
|
+
pandas_plots-0.11.24.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
|
10
|
+
pandas_plots-0.11.24.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
pandas_plots/hlp.py,sha256=N6NrbFagVMMX-ZnV0rIBEz82SeSoOkksfMcCap55W7E,16588
|
2
|
-
pandas_plots/pii.py,sha256=2WKE-W9s285jPdsTqCgt1uxuW4lj1PYCVOYB2fYDNwQ,2195
|
3
|
-
pandas_plots/pls.py,sha256=2V8zug64t69NmXU7sUL9QYiqH--BZOzPR0t91_bf0tw,35459
|
4
|
-
pandas_plots/tbl.py,sha256=A1SqvssDA4ofI_WJ-sdWIb9Bo5X-sELD8pley22Y4X4,28380
|
5
|
-
pandas_plots/ven.py,sha256=2x3ACo2vSfO3q6fv-UdDQ0h1SJyt8WChBGgE5SDCdCk,11673
|
6
|
-
pandas_plots-0.11.23.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
|
7
|
-
pandas_plots-0.11.23.dist-info/METADATA,sha256=QykpzT1s6EXbyXHA7P9Vrw_YbEMh4_wWeDtgKxl5D-g,7220
|
8
|
-
pandas_plots-0.11.23.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
9
|
-
pandas_plots-0.11.23.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
|
10
|
-
pandas_plots-0.11.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|