pandas-plots 0.12.4__tar.gz → 0.12.5__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.4/src/pandas_plots.egg-info → pandas_plots-0.12.5}/PKG-INFO +3 -3
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/README.md +1 -1
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/setup.cfg +2 -2
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots/pls.py +58 -24
- {pandas_plots-0.12.4 → pandas_plots-0.12.5/src/pandas_plots.egg-info}/PKG-INFO +3 -3
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots.egg-info/requires.txt +1 -1
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/LICENSE +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/pyproject.toml +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots/hlp.py +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots/pii.py +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots/tbl.py +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots/ven.py +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots.egg-info/SOURCES.txt +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots.egg-info/dependency_links.txt +0 -0
- {pandas_plots-0.12.4 → pandas_plots-0.12.5}/src/pandas_plots.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: pandas-plots
|
3
|
-
Version: 0.12.
|
3
|
+
Version: 0.12.5
|
4
4
|
Summary: A collection of helper for table handling and visualization
|
5
5
|
Home-page: https://github.com/smeisegeier/pandas-plots
|
6
6
|
Author: smeisegeier
|
@@ -20,7 +20,7 @@ Requires-Python: >=3.10
|
|
20
20
|
Description-Content-Type: text/markdown
|
21
21
|
License-File: LICENSE
|
22
22
|
Requires-Dist: pandas>=2.0.0
|
23
|
-
Requires-Dist: plotly
|
23
|
+
Requires-Dist: plotly<6
|
24
24
|
Requires-Dist: matplotlib>=3.8.2
|
25
25
|
Requires-Dist: matplotlib-venn==0.11.10
|
26
26
|
Requires-Dist: seaborn>=0.13.2
|
@@ -96,7 +96,7 @@ tbl.show_num_df(
|
|
96
96
|
- `plot_histogram()` histogram for one or more **numerical** columns
|
97
97
|
- `plot_joints()` a joint plot for **exactly two numerical** columns
|
98
98
|
- `plot_quadrants()` quickly shows a 2x2 heatmap
|
99
|
-
- 🆕 `
|
99
|
+
- 🆕 `plot_facet_stacked_bars()` shows stacked bars for a facet value as subplots
|
100
100
|
<br>
|
101
101
|
|
102
102
|
- `ven` offers functions for _venn diagrams_
|
@@ -61,7 +61,7 @@ tbl.show_num_df(
|
|
61
61
|
- `plot_histogram()` histogram for one or more **numerical** columns
|
62
62
|
- `plot_joints()` a joint plot for **exactly two numerical** columns
|
63
63
|
- `plot_quadrants()` quickly shows a 2x2 heatmap
|
64
|
-
- 🆕 `
|
64
|
+
- 🆕 `plot_facet_stacked_bars()` shows stacked bars for a facet value as subplots
|
65
65
|
<br>
|
66
66
|
|
67
67
|
- `ven` offers functions for _venn diagrams_
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[metadata]
|
2
2
|
name = pandas-plots
|
3
|
-
version = 0.12.
|
3
|
+
version = 0.12.5
|
4
4
|
author = smeisegeier
|
5
5
|
author_email = dexterDSDo@googlemail.com
|
6
6
|
description = A collection of helper for table handling and visualization
|
@@ -26,7 +26,7 @@ classifiers =
|
|
26
26
|
python_requires = >=3.10
|
27
27
|
install_requires =
|
28
28
|
pandas >= 2.0.0
|
29
|
-
plotly
|
29
|
+
plotly < 6
|
30
30
|
matplotlib >= 3.8.2
|
31
31
|
matplotlib-venn == 0.11.10
|
32
32
|
seaborn >= 0.13.2
|
@@ -78,7 +78,7 @@ def assign_column_colors(columns, color_palette, null_label):
|
|
78
78
|
raise ValueError(f"Invalid color palette: {color_palette}")
|
79
79
|
|
80
80
|
colors = {col: palette[i % len(palette)] for i, col in enumerate(sorted(columns))}
|
81
|
-
colors[null_label] = "
|
81
|
+
colors[null_label] = "lightgray"
|
82
82
|
return colors
|
83
83
|
|
84
84
|
### main functions
|
@@ -192,12 +192,32 @@ def plot_stacked_bars(
|
|
192
192
|
) -> object:
|
193
193
|
"""
|
194
194
|
Generates a stacked bar plot using the provided DataFrame.
|
195
|
-
Updated to assign colors using `assign_column_colors` with nulls colored grey.
|
196
195
|
|
197
196
|
Parameters:
|
198
|
-
|
199
|
-
-
|
200
|
-
-
|
197
|
+
- df (pd.DataFrame): The input DataFrame with at least two categorical columns and one numerical column.
|
198
|
+
- top_n_index (int): Limit the number of categories displayed on the index axis.
|
199
|
+
- top_n_color (int): Limit the number of categories displayed in the color legend.
|
200
|
+
- dropna (bool): If True, removes rows with missing values; otherwise, replaces them with `null_label`.
|
201
|
+
- swap (bool): If True, swaps the first two columns.
|
202
|
+
- normalize (bool): If True, normalizes numerical values between 0 and 1.
|
203
|
+
- relative (bool): If True, normalizes the bars to a percentage scale.
|
204
|
+
- orientation (Literal["h", "v"]): Defines the orientation of the bars ("v" for vertical, "h" for horizontal).
|
205
|
+
- height (int): Height of the plot.
|
206
|
+
- width (int): Width of the plot.
|
207
|
+
- title (str): Custom title for the plot.
|
208
|
+
- renderer (Literal["png", "svg", None]): Defines the output format.
|
209
|
+
- caption (str): Optional caption for additional context.
|
210
|
+
- sort_values (bool):
|
211
|
+
- If True, sorts bars by the sum of their values (descending).
|
212
|
+
- If False, sorts bars alphabetically.
|
213
|
+
- show_total (bool): If True, adds a row with the total sum of all categories.
|
214
|
+
- precision (int): Number of decimal places for numerical values.
|
215
|
+
- png_path (Path | str): If specified, saves the plot as a PNG file.
|
216
|
+
- color_palette (str): Name of the color palette to use.
|
217
|
+
- null_label (str): Label for null values.
|
218
|
+
|
219
|
+
Returns:
|
220
|
+
- A Plotly figure object representing the stacked bar chart.
|
201
221
|
"""
|
202
222
|
BAR_LENGTH_MULTIPLIER = 1.05
|
203
223
|
|
@@ -211,6 +231,8 @@ def plot_stacked_bars(
|
|
211
231
|
print("❌ first 2 columns must be str")
|
212
232
|
return
|
213
233
|
|
234
|
+
df = df.copy() # Copy the input DataFrame to avoid modifying the original
|
235
|
+
|
214
236
|
# * add count column[2] as a service if none is present
|
215
237
|
if len(df.columns) == 2:
|
216
238
|
df["cnt"] = 1
|
@@ -251,6 +273,18 @@ def plot_stacked_bars(
|
|
251
273
|
.sum()
|
252
274
|
.reset_index()
|
253
275
|
)
|
276
|
+
|
277
|
+
# * Sorting logic based on sort_values
|
278
|
+
if sort_values:
|
279
|
+
sort_order = (
|
280
|
+
df.groupby(col_index)[df.columns[2]].sum().sort_values(ascending=False).index
|
281
|
+
)
|
282
|
+
else:
|
283
|
+
sort_order = sorted(df[col_index].unique()) # Alphabetical order
|
284
|
+
|
285
|
+
# * Convert to categorical with explicit ordering
|
286
|
+
df[col_index] = pd.Categorical(df[col_index], categories=sort_order, ordered=True)
|
287
|
+
|
254
288
|
|
255
289
|
# * calculate n
|
256
290
|
divider = 2 if show_total else 1
|
@@ -264,7 +298,7 @@ def plot_stacked_bars(
|
|
264
298
|
caption = _set_caption(caption)
|
265
299
|
|
266
300
|
# * plot
|
267
|
-
|
301
|
+
fig = px.bar(
|
268
302
|
df,
|
269
303
|
x=col_index if orientation == "v" else df.columns[2],
|
270
304
|
y=df.columns[2] if orientation == "v" else col_index,
|
@@ -277,6 +311,7 @@ def plot_stacked_bars(
|
|
277
311
|
width=width,
|
278
312
|
height=height,
|
279
313
|
color_discrete_map=column_colors, # Use assigned colors
|
314
|
+
category_orders={col_index: list(df[col_index].cat.categories)}, # <- Add this line
|
280
315
|
)
|
281
316
|
# * get longest bar
|
282
317
|
bar_max = (
|
@@ -286,14 +321,14 @@ def plot_stacked_bars(
|
|
286
321
|
# * ignore if bar mode is on
|
287
322
|
if not relative:
|
288
323
|
if orientation == "v":
|
289
|
-
|
324
|
+
fig.update_yaxes(range=[0, bar_max])
|
290
325
|
else:
|
291
|
-
|
326
|
+
fig.update_xaxes(range=[0, bar_max])
|
292
327
|
else:
|
293
|
-
|
328
|
+
fig.update_layout(barnorm="percent")
|
294
329
|
|
295
330
|
# * set title properties
|
296
|
-
|
331
|
+
fig.update_layout(
|
297
332
|
title={
|
298
333
|
# 'x': 0.1,
|
299
334
|
"y": 0.95,
|
@@ -308,27 +343,26 @@ def plot_stacked_bars(
|
|
308
343
|
# * set dtick
|
309
344
|
if orientation == "h":
|
310
345
|
if relative:
|
311
|
-
|
346
|
+
fig.update_xaxes(dtick=5)
|
312
347
|
elif normalize:
|
313
|
-
|
348
|
+
fig.update_xaxes(dtick=0.05)
|
314
349
|
else:
|
315
350
|
if relative:
|
316
|
-
|
351
|
+
fig.update_yaxes(dtick=5)
|
317
352
|
elif normalize:
|
318
|
-
|
353
|
+
fig.update_yaxes(dtick=0.05)
|
319
354
|
|
320
355
|
# * show grids, set to smaller distance on pct scale
|
321
|
-
|
322
|
-
|
356
|
+
fig.update_xaxes(showgrid=True, gridwidth=1)
|
357
|
+
fig.update_yaxes(showgrid=True, gridwidth=1)
|
323
358
|
|
324
359
|
# * save to png if path is provided
|
325
360
|
if png_path is not None:
|
326
|
-
|
327
|
-
|
328
|
-
_fig.show(renderer)
|
361
|
+
fig.write_image(Path(png_path).as_posix())
|
329
362
|
|
330
|
-
|
363
|
+
fig.show(renderer=renderer)
|
331
364
|
|
365
|
+
return fig
|
332
366
|
|
333
367
|
|
334
368
|
def plot_bars(
|
@@ -1189,17 +1223,17 @@ def plot_facet_stacked_bars(
|
|
1189
1223
|
unique_rows = len(aggregated_df)
|
1190
1224
|
axis_details = []
|
1191
1225
|
if top_n_index > 0:
|
1192
|
-
axis_details.append(f"
|
1226
|
+
axis_details.append(f"TOP {top_n_index} [{original_column_names[0]}]")
|
1193
1227
|
else:
|
1194
1228
|
axis_details.append(f"[{original_column_names[0]}]")
|
1195
1229
|
|
1196
1230
|
if top_n_columns > 0:
|
1197
|
-
axis_details.append(f"
|
1231
|
+
axis_details.append(f"TOP {top_n_columns} [{original_column_names[1]}]")
|
1198
1232
|
else:
|
1199
1233
|
axis_details.append(f"[{original_column_names[1]}]")
|
1200
1234
|
|
1201
1235
|
if top_n_facet > 0:
|
1202
|
-
axis_details.append(f"
|
1236
|
+
axis_details.append(f"TOP {top_n_facet} [{original_column_names[2]}]")
|
1203
1237
|
else:
|
1204
1238
|
axis_details.append(f"[{original_column_names[2]}]")
|
1205
1239
|
|
@@ -1218,6 +1252,6 @@ def plot_facet_stacked_bars(
|
|
1218
1252
|
png_path = Path(png_path)
|
1219
1253
|
fig.write_image(str(png_path))
|
1220
1254
|
|
1221
|
-
fig.show(renderer)
|
1255
|
+
fig.show(renderer=renderer)
|
1222
1256
|
|
1223
1257
|
return fig
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: pandas-plots
|
3
|
-
Version: 0.12.
|
3
|
+
Version: 0.12.5
|
4
4
|
Summary: A collection of helper for table handling and visualization
|
5
5
|
Home-page: https://github.com/smeisegeier/pandas-plots
|
6
6
|
Author: smeisegeier
|
@@ -20,7 +20,7 @@ Requires-Python: >=3.10
|
|
20
20
|
Description-Content-Type: text/markdown
|
21
21
|
License-File: LICENSE
|
22
22
|
Requires-Dist: pandas>=2.0.0
|
23
|
-
Requires-Dist: plotly
|
23
|
+
Requires-Dist: plotly<6
|
24
24
|
Requires-Dist: matplotlib>=3.8.2
|
25
25
|
Requires-Dist: matplotlib-venn==0.11.10
|
26
26
|
Requires-Dist: seaborn>=0.13.2
|
@@ -96,7 +96,7 @@ tbl.show_num_df(
|
|
96
96
|
- `plot_histogram()` histogram for one or more **numerical** columns
|
97
97
|
- `plot_joints()` a joint plot for **exactly two numerical** columns
|
98
98
|
- `plot_quadrants()` quickly shows a 2x2 heatmap
|
99
|
-
- 🆕 `
|
99
|
+
- 🆕 `plot_facet_stacked_bars()` shows stacked bars for a facet value as subplots
|
100
100
|
<br>
|
101
101
|
|
102
102
|
- `ven` offers functions for _venn diagrams_
|
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
|