pandas-plots 0.12.20__tar.gz → 0.12.21__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.
- {pandas_plots-0.12.20/src/pandas_plots.egg-info → pandas_plots-0.12.21}/PKG-INFO +1 -1
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/setup.cfg +1 -1
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots/hlp.py +18 -11
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots/pls.py +25 -10
- {pandas_plots-0.12.20 → pandas_plots-0.12.21/src/pandas_plots.egg-info}/PKG-INFO +1 -1
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/LICENSE +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/README.md +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/pyproject.toml +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots/pii.py +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots/tbl.py +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots/ven.py +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/SOURCES.txt +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/dependency_links.txt +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/pii.py +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/requires.txt +0 -0
- {pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/top_level.txt +0 -0
@@ -22,29 +22,34 @@ from PIL import Image
|
|
22
22
|
URL_REGEX = r"^(?:http|ftp)s?://" # https://stackoverflow.com/a/1617386
|
23
23
|
|
24
24
|
|
25
|
-
def mean_confidence_interval(df, confidence=0.95):
|
25
|
+
def mean_confidence_interval(df, confidence=0.95, use_median=False):
|
26
26
|
"""
|
27
|
-
Calculate the mean and confidence interval of the input dataframe.
|
28
|
-
|
27
|
+
Calculate the mean or median and confidence interval of the input dataframe.
|
28
|
+
Source: https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
|
29
29
|
|
30
30
|
Parameters:
|
31
31
|
df (array-like): The input dataframe.
|
32
32
|
confidence (float, optional): The confidence level for the interval. Defaults to 0.95.
|
33
|
+
use_median (bool, optional): If True, calculates median and confidence interval instead of mean. Defaults to False.
|
33
34
|
|
34
35
|
Returns:
|
35
|
-
tuple: A tuple containing the mean, interval, lower bound, and upper bound.
|
36
|
+
tuple: A tuple containing the central value (mean or median), interval, lower bound, and upper bound.
|
36
37
|
"""
|
37
38
|
df = to_series(df)
|
38
39
|
if df is None:
|
39
40
|
return None
|
40
41
|
a = 1.0 * np.array(df)
|
41
42
|
n = len(a)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
|
44
|
+
if use_median:
|
45
|
+
median = np.median(a)
|
46
|
+
se = 1.253 * scipy.stats.sem(a) # Approximate standard error for median
|
47
|
+
margin = se * scipy.stats.t.ppf((1 + confidence) / 2.0, n - 1)
|
48
|
+
return median, margin, median - margin, median + margin
|
49
|
+
else:
|
50
|
+
mean, se = np.mean(a), scipy.stats.sem(a)
|
51
|
+
margin = se * scipy.stats.t.ppf((1 + confidence) / 2.0, n - 1)
|
52
|
+
return mean, margin, mean - margin, mean + margin
|
48
53
|
|
49
54
|
# # * Alternative
|
50
55
|
# # from statistics import NormalDist
|
@@ -542,7 +547,9 @@ def add_measures_to_pyg_config(json_path: str, nodes: list[tuple[str, str]] = [(
|
|
542
547
|
|
543
548
|
Example
|
544
549
|
-------
|
545
|
-
`add_measures_to_pyg_config('config.json', [('cnt_tum', 'count(distinct z_tum_id)')], strict=True)`
|
550
|
+
default: `add_measures_to_pyg_config('config.json', [('cnt_tum', 'count(distinct z_tum_id)')], strict=True)`
|
551
|
+
|
552
|
+
usage: start pygwalker with empty config file but defined config path. make changes on the chart, save the config file. then run this function again - measures will be added
|
546
553
|
"""
|
547
554
|
if not os.path.exists(json_path):
|
548
555
|
if strict:
|
@@ -500,6 +500,7 @@ def plot_bars(
|
|
500
500
|
width: int = 1600,
|
501
501
|
title: str = None,
|
502
502
|
use_ci: bool = False,
|
503
|
+
ci_agg: Literal["mean", "median"] = "mean",
|
503
504
|
precision: int = 0,
|
504
505
|
renderer: Literal["png", "svg", None] = "png",
|
505
506
|
png_path: Path | str = None,
|
@@ -569,9 +570,9 @@ def plot_bars(
|
|
569
570
|
dropna=False,
|
570
571
|
)
|
571
572
|
.agg(
|
572
|
-
mean=(col_name,
|
573
|
+
mean=(col_name, ci_agg),
|
573
574
|
# * retrieve margin from custom func
|
574
|
-
margin=(col_name, lambda x: mean_confidence_interval(x)[1]),
|
575
|
+
margin=(col_name, lambda x: mean_confidence_interval(x, use_median = (ci_agg == "median"))[1]),
|
575
576
|
)
|
576
577
|
.reset_index()
|
577
578
|
)
|
@@ -653,7 +654,7 @@ def plot_bars(
|
|
653
654
|
|
654
655
|
# * title str n
|
655
656
|
_title_str_n = (
|
656
|
-
f", n={n_len:_} ({n:_})" if not use_ci else f", n={n_len:_})<br><sub>ci(95) on
|
657
|
+
f", n={n_len:_} ({n:_})" if not use_ci else f", n={n_len:_})<br><sub>ci(95) on {ci_agg}s<sub>"
|
657
658
|
)
|
658
659
|
|
659
660
|
# * title str na
|
@@ -965,6 +966,7 @@ def plot_box(
|
|
965
966
|
violin: bool = False,
|
966
967
|
x_min: float = None,
|
967
968
|
x_max: float = None,
|
969
|
+
use_log: bool = False,
|
968
970
|
png_path: Path | str = None,
|
969
971
|
) -> object:
|
970
972
|
"""
|
@@ -977,10 +979,13 @@ def plot_box(
|
|
977
979
|
height: The height of the plot.
|
978
980
|
width: The width of the plot.
|
979
981
|
annotations: Whether to add annotations to the plot.
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
982
|
+
summary: Whether to add a summary table to the plot.
|
983
|
+
caption: The caption for the plot.
|
984
|
+
title: The title of the plot.
|
985
|
+
violin: Use violin plot or not.
|
986
|
+
x_min: The minimum value for the x-axis scale (max and min must be set).
|
987
|
+
x_max: The maximum value for the x-axis scale (max and min must be set).
|
988
|
+
use_log: Use logarithmic scale for the axis.
|
984
989
|
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
985
990
|
|
986
991
|
Returns:
|
@@ -993,7 +998,7 @@ def plot_box(
|
|
993
998
|
# * drop na to keep scipy sane
|
994
999
|
n_ = len(ser)
|
995
1000
|
ser.dropna(inplace=True)
|
996
|
-
n = len(ser)
|
1001
|
+
# n = len(ser)
|
997
1002
|
|
998
1003
|
# hack
|
999
1004
|
median = ser.median()
|
@@ -1011,7 +1016,6 @@ def plot_box(
|
|
1011
1016
|
lvl3 = height * 0.25
|
1012
1017
|
|
1013
1018
|
caption = _set_caption(caption)
|
1014
|
-
|
1015
1019
|
dict = {
|
1016
1020
|
"data_frame": ser,
|
1017
1021
|
"orientation": "h",
|
@@ -1020,7 +1024,9 @@ def plot_box(
|
|
1020
1024
|
"width": width,
|
1021
1025
|
"points": points,
|
1022
1026
|
# 'box':True,
|
1023
|
-
"
|
1027
|
+
"log_x": use_log, # * logarithmic scale, axis is always x
|
1028
|
+
# "notched": True,
|
1029
|
+
"title": f"{caption}[{ser.name}], n = {n_:_}" if not title else title,
|
1024
1030
|
}
|
1025
1031
|
|
1026
1032
|
fig = px.violin(**{**dict, "box": True}) if violin else px.box(**dict)
|
@@ -1119,6 +1125,8 @@ def plot_boxes(
|
|
1119
1125
|
annotations: bool = True,
|
1120
1126
|
summary: bool = True,
|
1121
1127
|
title: str = None,
|
1128
|
+
use_log: bool = False,
|
1129
|
+
box_width: float = 0.5,
|
1122
1130
|
png_path: Path | str = None,
|
1123
1131
|
) -> object:
|
1124
1132
|
"""
|
@@ -1133,6 +1141,7 @@ def plot_boxes(
|
|
1133
1141
|
width (int): The width of the plot.
|
1134
1142
|
annotations (bool): Whether to add annotations to the plot.
|
1135
1143
|
summary (bool): Whether to add a summary to the plot.
|
1144
|
+
use_log (bool): Whether to use logarithmic scale for the plot.
|
1136
1145
|
png_path (Path | str, optional): The path to save the image as a png file. Defaults to None.
|
1137
1146
|
|
1138
1147
|
Returns:
|
@@ -1170,11 +1179,14 @@ def plot_boxes(
|
|
1170
1179
|
df,
|
1171
1180
|
x=df.iloc[:, 0],
|
1172
1181
|
y=df.iloc[:, 1],
|
1182
|
+
color=df.iloc[:, 0],
|
1173
1183
|
template="plotly_dark" if os.getenv("THEME") == "dark" else "plotly",
|
1174
1184
|
orientation="v",
|
1175
1185
|
height=height,
|
1176
1186
|
width=width,
|
1177
1187
|
points=points,
|
1188
|
+
log_y=use_log,
|
1189
|
+
# color_discrete_sequence=px.colors.qualitative.Plotly,
|
1178
1190
|
title=(
|
1179
1191
|
f"{caption}[{df.columns[0]}] on [{df.columns[1]}], n = {len(df):_.0f}"
|
1180
1192
|
if not title
|
@@ -1245,6 +1257,9 @@ def plot_boxes(
|
|
1245
1257
|
|
1246
1258
|
fig.update_xaxes(title_text=df.columns[0])
|
1247
1259
|
fig.update_yaxes(title_text=df.columns[1])
|
1260
|
+
fig.update_layout(boxmode="group") # Ensures boxes are not too compressed
|
1261
|
+
fig.update_layout(showlegend=False)
|
1262
|
+
fig.update_traces(marker=dict(size=7), width=box_width) # Adjust width (default ~0.5)
|
1248
1263
|
|
1249
1264
|
fig.show("png")
|
1250
1265
|
if summary:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pandas_plots-0.12.20 → pandas_plots-0.12.21}/src/pandas_plots.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|