pandas-plots 0.15.12__tar.gz → 0.16.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.
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/PKG-INFO +2 -1
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/README.md +1 -0
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/pyproject.toml +1 -1
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/src/pandas_plots/pls.py +83 -0
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/src/pandas_plots/tbl.py +2 -3
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/src/pandas_plots/__init__.py +0 -0
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/src/pandas_plots/hlp.py +0 -0
- {pandas_plots-0.15.12 → pandas_plots-0.16.0}/src/pandas_plots/ven.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: pandas-plots
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.16.0
|
4
4
|
Summary: A collection of helper for table handling and visualization
|
5
5
|
Keywords: tables,pivot,plotly,venn,plot,vizualization
|
6
6
|
Author: smeisegeier
|
@@ -99,6 +99,7 @@ tbl.show_num_df(
|
|
99
99
|
- `plot_quadrants()` quickly shows a 2x2 heatmap
|
100
100
|
- `plot_facet_stacked_bars()` shows stacked bars for a facet value as subplots
|
101
101
|
- `plot_sankey()` generates a Sankey diagram
|
102
|
+
- `plot_pie()` generates a pie chart
|
102
103
|
<br>
|
103
104
|
|
104
105
|
- `ven` offers functions for _venn diagrams_
|
@@ -65,6 +65,7 @@ tbl.show_num_df(
|
|
65
65
|
- `plot_quadrants()` quickly shows a 2x2 heatmap
|
66
66
|
- `plot_facet_stacked_bars()` shows stacked bars for a facet value as subplots
|
67
67
|
- `plot_sankey()` generates a Sankey diagram
|
68
|
+
- `plot_pie()` generates a pie chart
|
68
69
|
<br>
|
69
70
|
|
70
71
|
- `ven` offers functions for _venn diagrams_
|
@@ -11,8 +11,10 @@ import seaborn as sb
|
|
11
11
|
from matplotlib import pyplot as plt
|
12
12
|
from plotly import express as px
|
13
13
|
import plotly.graph_objects as go
|
14
|
+
import plotly.io as pio
|
14
15
|
from plotly.subplots import make_subplots
|
15
16
|
import plotly # needed for return types
|
17
|
+
|
16
18
|
import re
|
17
19
|
|
18
20
|
from .hlp import *
|
@@ -1889,6 +1891,86 @@ def plot_sankey(
|
|
1889
1891
|
fig.update_layout(title_text=chart_title, font_size=font_size, width=width, height=height)
|
1890
1892
|
fig.show(renderer=renderer or os.getenv("RENDERER"), width=width, height=height)
|
1891
1893
|
|
1894
|
+
|
1895
|
+
def plot_pie(
|
1896
|
+
data: pd.Series | pd.DataFrame,
|
1897
|
+
caption: str = None,
|
1898
|
+
width=800,
|
1899
|
+
height=500,
|
1900
|
+
renderer="notebook",
|
1901
|
+
donut_size=0,
|
1902
|
+
):
|
1903
|
+
"""
|
1904
|
+
Creates and displays a pie or donut chart using Plotly Express.
|
1905
|
+
|
1906
|
+
Args:
|
1907
|
+
data (pd.Series or pd.DataFrame): The data to plot.
|
1908
|
+
If a DataFrame, it must have only one column. The index will be
|
1909
|
+
used for labels and the values for the pie slice sizes.
|
1910
|
+
caption (str): The title for the plot.
|
1911
|
+
height (int, optional): The height of the plot in pixels. Defaults to 800.
|
1912
|
+
width (int, optional): The width of the plot in pixels. Defaults to 500.
|
1913
|
+
renderer (str, optional): The Plotly renderer to use (e.g., 'notebook', 'png', 'svg').
|
1914
|
+
Defaults to 'notebook'.
|
1915
|
+
donut_size (float, optional): A value between 0 and 1 to create a donut chart.
|
1916
|
+
A value of 0 results in a regular pie chart. Defaults to 0.
|
1917
|
+
"""
|
1918
|
+
# Store the original renderer to restore it later
|
1919
|
+
# original_renderer = pio.renderers.default
|
1920
|
+
# ? override renderer
|
1921
|
+
original_renderer = "notebook"
|
1922
|
+
|
1923
|
+
# * 1. Check for correct data type first
|
1924
|
+
if not isinstance(data, (pd.Series, pd.DataFrame)):
|
1925
|
+
print("Error: Data must be a pandas Series or DataFrame.")
|
1926
|
+
return
|
1927
|
+
|
1928
|
+
# * 2. **CONVERT SERIES TO DATAFRAME**
|
1929
|
+
if isinstance(data, pd.Series):
|
1930
|
+
# * Get the name of the Series
|
1931
|
+
label = data.name
|
1932
|
+
# * Convert the Series to a DataFrame with a column named 'values'
|
1933
|
+
# * The index will automatically become the DataFrame index
|
1934
|
+
data = data.to_frame(name="values")
|
1935
|
+
else:
|
1936
|
+
# * Get the name of the first column
|
1937
|
+
label = data.columns[0]
|
1938
|
+
|
1939
|
+
# * 3. Ensure the DataFrame has only one column
|
1940
|
+
if len(data.columns) != 1:
|
1941
|
+
print("Error: DataFrame must have exactly one column for this function.")
|
1942
|
+
return
|
1943
|
+
|
1944
|
+
# * Set the temporary renderer for the plot
|
1945
|
+
pio.renderers.default = renderer
|
1946
|
+
|
1947
|
+
# * Get the number of observations
|
1948
|
+
n = len(data)
|
1949
|
+
|
1950
|
+
# * take 1st (only) column and use value counts to get distribution
|
1951
|
+
data = data.iloc[:, 0].value_counts()
|
1952
|
+
|
1953
|
+
# * 4. Create the figure
|
1954
|
+
fig = px.pie(
|
1955
|
+
data,
|
1956
|
+
values=data,
|
1957
|
+
names=data.index,
|
1958
|
+
title=f"{_set_caption(caption)}{label}, n = {n:_}",
|
1959
|
+
height=height,
|
1960
|
+
width=width,
|
1961
|
+
hole=donut_size,
|
1962
|
+
template="plotly_dark" if os.getenv("THEME") == "dark" else "plotly",
|
1963
|
+
)
|
1964
|
+
|
1965
|
+
# * Display the plot
|
1966
|
+
fig.show()
|
1967
|
+
|
1968
|
+
# finally:
|
1969
|
+
# * 5. Restore the original renderer, ensuring it's always done
|
1970
|
+
pio.renderers.default = original_renderer
|
1971
|
+
|
1972
|
+
|
1973
|
+
|
1892
1974
|
# * extend objects to enable chaining
|
1893
1975
|
pd.DataFrame.plot_bars = plot_bars
|
1894
1976
|
pd.DataFrame.plot_stacked_bars = plot_stacked_bars
|
@@ -1899,3 +1981,4 @@ pd.DataFrame.plot_quadrants = plot_quadrants
|
|
1899
1981
|
pd.DataFrame.plot_histogram = plot_histogram
|
1900
1982
|
pd.DataFrame.plot_joint = plot_joint
|
1901
1983
|
pd.DataFrame.plot_sankey = plot_sankey
|
1984
|
+
pd.DataFrame.plot_pie = plot_pie
|
@@ -112,7 +112,7 @@ def describe_df(
|
|
112
112
|
df=df,
|
113
113
|
caption="dataframe",
|
114
114
|
use_plot=True,
|
115
|
-
renderer=
|
115
|
+
renderer=None,
|
116
116
|
template="plotly",
|
117
117
|
fig_cols=3,
|
118
118
|
fig_offset=None,
|
@@ -264,7 +264,7 @@ def describe_df(
|
|
264
264
|
)
|
265
265
|
|
266
266
|
fig.show(
|
267
|
-
renderer,
|
267
|
+
renderer=renderer or os.getenv("RENDERER"),
|
268
268
|
width=fig_width * fig_cols, # <-- Set width here
|
269
269
|
height=fig_rowheight * fig_rows, # <-- Set height here
|
270
270
|
)
|
@@ -273,7 +273,6 @@ def describe_df(
|
|
273
273
|
import missingno as msno
|
274
274
|
msno.matrix(df_, figsize=missing_figsize)
|
275
275
|
|
276
|
-
|
277
276
|
def pivot_df(
|
278
277
|
df: pd.DataFrame,
|
279
278
|
dropna: bool = False,
|
File without changes
|
File without changes
|
File without changes
|