MatplotLibAPI 3.2.0__tar.gz → 3.2.2__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.
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Bubble.py +55 -14
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Composite.py +7 -7
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Table.py +29 -4
- matplotlibapi-3.2.2/MatplotLibAPI/Timeserie.py +128 -0
- matplotlibapi-3.2.2/MatplotLibAPI/__init__.py +259 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2/MatplotLibAPI.egg-info}/PKG-INFO +1 -1
- {matplotlibapi-3.2.0/MatplotLibAPI.egg-info → matplotlibapi-3.2.2}/PKG-INFO +1 -1
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/pyproject.toml +1 -1
- matplotlibapi-3.2.0/MatplotLibAPI/Timeserie.py +0 -97
- matplotlibapi-3.2.0/MatplotLibAPI/__init__.py +0 -149
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/LICENSE +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Network.py +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Pivot.py +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/StyleTemplate.py +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI/Treemap.py +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI.egg-info/SOURCES.txt +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI.egg-info/dependency_links.txt +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI.egg-info/requires.txt +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/MatplotLibAPI.egg-info/top_level.txt +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/README.md +0 -0
- {matplotlibapi-3.2.0 → matplotlibapi-3.2.2}/setup.cfg +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# Hint for Visual Code Python Interactive window
|
|
2
2
|
# %%
|
|
3
|
-
from typing import Optional
|
|
3
|
+
from typing import Optional, Tuple
|
|
4
4
|
import pandas as pd
|
|
5
5
|
import matplotlib.pyplot as plt
|
|
6
6
|
from matplotlib.axes import Axes
|
|
7
|
+
from matplotlib.figure import Figure
|
|
7
8
|
import seaborn as sns
|
|
8
9
|
|
|
9
|
-
from .StyleTemplate import DynamicFuncFormatter, StyleTemplate, generate_ticks, string_formatter, bmk_formatter, percent_formatter, format_func,validate_dataframe
|
|
10
|
+
from .StyleTemplate import DynamicFuncFormatter, StyleTemplate, generate_ticks, string_formatter, bmk_formatter, percent_formatter, format_func, validate_dataframe
|
|
10
11
|
|
|
11
12
|
BUBBLE_STYLE_TEMPLATE = StyleTemplate(
|
|
12
13
|
format_funcs={"label": string_formatter,
|
|
@@ -18,7 +19,7 @@ BUBBLE_STYLE_TEMPLATE = StyleTemplate(
|
|
|
18
19
|
)
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
def
|
|
22
|
+
def plot_bubble_ax(
|
|
22
23
|
pd_df: pd.DataFrame,
|
|
23
24
|
label: str,
|
|
24
25
|
x: str,
|
|
@@ -30,6 +31,8 @@ def plot_bubble(
|
|
|
30
31
|
center_to_mean: bool = False,
|
|
31
32
|
sort_by: Optional[str] = None,
|
|
32
33
|
ascending: bool = False,
|
|
34
|
+
hline=False,
|
|
35
|
+
vline=False,
|
|
33
36
|
ax: Optional[Axes] = None):
|
|
34
37
|
|
|
35
38
|
validate_dataframe(pd_df, cols=[label, x, y, z], sort_by=sort_by)
|
|
@@ -92,17 +95,18 @@ def plot_bubble(
|
|
|
92
95
|
which='major',
|
|
93
96
|
colors=style.font_color,
|
|
94
97
|
labelsize=style.font_size)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
if vline:
|
|
99
|
+
ax.vlines(x=x_mean,
|
|
100
|
+
ymin=y_min,
|
|
101
|
+
ymax=y_max,
|
|
102
|
+
linestyle='--',
|
|
103
|
+
colors=style.font_color)
|
|
104
|
+
if hline:
|
|
105
|
+
ax.hlines(y=y_mean,
|
|
106
|
+
xmin=x_min,
|
|
107
|
+
xmax=x_max,
|
|
108
|
+
linestyle='--',
|
|
109
|
+
colors=style.font_color)
|
|
106
110
|
|
|
107
111
|
for index, row in plot_df.iterrows():
|
|
108
112
|
x_value = row[x]
|
|
@@ -121,4 +125,41 @@ def plot_bubble(
|
|
|
121
125
|
return ax
|
|
122
126
|
|
|
123
127
|
|
|
128
|
+
def plot_bubble_fig(
|
|
129
|
+
pd_df: pd.DataFrame,
|
|
130
|
+
label: str,
|
|
131
|
+
x: str,
|
|
132
|
+
y: str,
|
|
133
|
+
z: str,
|
|
134
|
+
title: Optional[str] = "Test",
|
|
135
|
+
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
136
|
+
max_values: int = BUBBLE_STYLE_TEMPLATE,
|
|
137
|
+
center_to_mean: bool = False,
|
|
138
|
+
sort_by: Optional[str] = None,
|
|
139
|
+
ascending: bool = False,
|
|
140
|
+
hline=False,
|
|
141
|
+
vline=False,
|
|
142
|
+
figsize: Tuple[float, float] = (19.2, 10.8)) -> Figure:
|
|
143
|
+
|
|
144
|
+
fig = plt.figure(figsize=figsize)
|
|
145
|
+
fig.patch.set_facecolor(style.background_color)
|
|
146
|
+
ax = fig.add_subplot()
|
|
147
|
+
ax = plot_bubble_ax(pd_df=pd_df,
|
|
148
|
+
label=label,
|
|
149
|
+
x=x,
|
|
150
|
+
y=y,
|
|
151
|
+
z=z,
|
|
152
|
+
title=title,
|
|
153
|
+
style=style,
|
|
154
|
+
max_values=max_values,
|
|
155
|
+
center_to_mean=center_to_mean,
|
|
156
|
+
sort_by=sort_by,
|
|
157
|
+
ascending=ascending,
|
|
158
|
+
hline=hline,
|
|
159
|
+
vline=vline,
|
|
160
|
+
ax=ax)
|
|
161
|
+
return fig
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
124
165
|
# endregion
|
|
@@ -5,12 +5,12 @@ import pandas as pd
|
|
|
5
5
|
import matplotlib.pyplot as plt
|
|
6
6
|
from matplotlib.figure import Figure
|
|
7
7
|
|
|
8
|
-
from .
|
|
9
|
-
from .
|
|
10
|
-
from .Table import plot_table
|
|
8
|
+
from .Bubble import plot_bubble_ax, BUBBLE_STYLE_TEMPLATE
|
|
9
|
+
from .Table import plot_table_ax
|
|
11
10
|
from .StyleTemplate import StyleTemplate, format_func, validate_dataframe
|
|
12
11
|
|
|
13
12
|
|
|
13
|
+
|
|
14
14
|
def plot_composite_bubble(
|
|
15
15
|
pd_df: pd.DataFrame,
|
|
16
16
|
label: str,
|
|
@@ -38,10 +38,10 @@ def plot_composite_bubble(
|
|
|
38
38
|
style.format_funcs = format_func(
|
|
39
39
|
style.format_funcs, label=label, x=x, y=y, z=z)
|
|
40
40
|
fig = plt.figure(figsize=figsize)
|
|
41
|
-
fig.patch.set_facecolor(
|
|
41
|
+
fig.patch.set_facecolor(style.background_color)
|
|
42
42
|
grid = plt.GridSpec(2, 2, height_ratios=[2, 1], width_ratios=[1, 1])
|
|
43
43
|
ax = fig.add_subplot(grid[0, 0:])
|
|
44
|
-
ax =
|
|
44
|
+
ax = plot_bubble_ax(pd_df=plot_df,
|
|
45
45
|
label=label,
|
|
46
46
|
x=x,
|
|
47
47
|
y=y,
|
|
@@ -64,7 +64,7 @@ def plot_composite_bubble(
|
|
|
64
64
|
style.format_funcs[z] = style.format_funcs["z"]
|
|
65
65
|
|
|
66
66
|
ax2 = fig.add_subplot(grid[1, 0])
|
|
67
|
-
ax2 =
|
|
67
|
+
ax2 = plot_table_ax(
|
|
68
68
|
pd_df=plot_df,
|
|
69
69
|
cols=[label, z, y, x],
|
|
70
70
|
title=f"Top {table_rows}",
|
|
@@ -75,7 +75,7 @@ def plot_composite_bubble(
|
|
|
75
75
|
style=style
|
|
76
76
|
)
|
|
77
77
|
ax3 = fig.add_subplot(grid[1, 1])
|
|
78
|
-
ax3 =
|
|
78
|
+
ax3 = plot_table_ax(
|
|
79
79
|
pd_df=plot_df,
|
|
80
80
|
cols=[label, z, y, x],
|
|
81
81
|
title=f"Worst {table_rows}",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
from typing import List, Optional
|
|
1
|
+
from typing import List, Optional, Tuple
|
|
2
2
|
import pandas as pd
|
|
3
3
|
import matplotlib.pyplot as plt
|
|
4
4
|
from matplotlib.axes import Axes
|
|
5
|
+
from matplotlib.figure import Figure
|
|
5
6
|
|
|
6
|
-
from .StyleTemplate import StyleTemplate, string_formatter,validate_dataframe
|
|
7
|
+
from .StyleTemplate import StyleTemplate, string_formatter, validate_dataframe
|
|
7
8
|
|
|
8
9
|
TABLE_STYLE_TEMPLATE = StyleTemplate(
|
|
9
10
|
background_color='black',
|
|
@@ -13,7 +14,7 @@ TABLE_STYLE_TEMPLATE = StyleTemplate(
|
|
|
13
14
|
)
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
def
|
|
17
|
+
def plot_table_ax(pd_df: pd.DataFrame,
|
|
17
18
|
cols: List[str],
|
|
18
19
|
title: Optional[str] = None,
|
|
19
20
|
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
@@ -23,7 +24,7 @@ def plot_table(pd_df: pd.DataFrame,
|
|
|
23
24
|
ax: Optional[Axes] = None
|
|
24
25
|
) -> Axes:
|
|
25
26
|
validate_dataframe(pd_df, cols=cols, sort_by=sort_by)
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
if not sort_by:
|
|
28
29
|
sort_by = cols[0]
|
|
29
30
|
|
|
@@ -64,3 +65,27 @@ def plot_table(pd_df: pd.DataFrame,
|
|
|
64
65
|
ax.set_title(title, color=style.font_color, fontsize=style.font_size*2)
|
|
65
66
|
ax.title.set_position([0.5, 1.05])
|
|
66
67
|
return ax
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def plot_table_fig(pd_df: pd.DataFrame,
|
|
71
|
+
cols: List[str],
|
|
72
|
+
title: Optional[str] = None,
|
|
73
|
+
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
74
|
+
max_values: int = 20,
|
|
75
|
+
sort_by: Optional[str] = None,
|
|
76
|
+
ascending: bool = False,
|
|
77
|
+
figsize: Tuple[float, float] = (19.2, 10.8)
|
|
78
|
+
) -> Figure:
|
|
79
|
+
fig = plt.figure(figsize=figsize)
|
|
80
|
+
fig.patch.set_facecolor(style.background_color)
|
|
81
|
+
ax = fig.add_subplot()
|
|
82
|
+
ax = plot_table_ax(pd_df,
|
|
83
|
+
cols,
|
|
84
|
+
title,
|
|
85
|
+
style,
|
|
86
|
+
max_values,
|
|
87
|
+
sort_by,
|
|
88
|
+
ascending,
|
|
89
|
+
ax
|
|
90
|
+
)
|
|
91
|
+
return fig
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Hint for Visual Code Python Interactive window
|
|
2
|
+
# %%
|
|
3
|
+
from typing import Optional, Tuple
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
from matplotlib.figure import Figure
|
|
7
|
+
from matplotlib.axes import Axes
|
|
8
|
+
import seaborn as sns
|
|
9
|
+
|
|
10
|
+
from .StyleTemplate import DynamicFuncFormatter, StyleTemplate, string_formatter, bmk_formatter, format_func, validate_dataframe
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
TIMESERIE_STYLE_TEMPLATE = StyleTemplate(
|
|
14
|
+
palette='rocket',
|
|
15
|
+
format_funcs={"y": bmk_formatter, "label": string_formatter}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# region Line
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def plot_timeserie_ax(pd_df: pd.DataFrame,
|
|
22
|
+
label: str,
|
|
23
|
+
x: str,
|
|
24
|
+
y: str,
|
|
25
|
+
title: Optional[str] = None,
|
|
26
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
27
|
+
max_values: int = 100,
|
|
28
|
+
sort_by: Optional[str] = None,
|
|
29
|
+
ascending: bool = False,
|
|
30
|
+
std: bool = False,
|
|
31
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
32
|
+
|
|
33
|
+
validate_dataframe(pd_df, cols=[label, x, y], sort_by=sort_by)
|
|
34
|
+
style.format_funcs = format_func(style.format_funcs, label=label, x=x, y=y)
|
|
35
|
+
|
|
36
|
+
df = pd_df[[label, x, y]].sort_values(by=[label, x])
|
|
37
|
+
df[x] = pd.to_datetime(df[x])
|
|
38
|
+
df.set_index(x, inplace=True)
|
|
39
|
+
|
|
40
|
+
sns.set_palette(style.palette)
|
|
41
|
+
# Colors for each group
|
|
42
|
+
colors = sns.color_palette(n_colors=len(df.columns))
|
|
43
|
+
if ax is None:
|
|
44
|
+
ax = plt.gca()
|
|
45
|
+
|
|
46
|
+
# Get unique dimension_types
|
|
47
|
+
label_types = df[label].unique()
|
|
48
|
+
|
|
49
|
+
# Colors for each group
|
|
50
|
+
colors = sns.color_palette(n_colors=len(label_types))
|
|
51
|
+
|
|
52
|
+
for label_type, color in zip(label_types, colors):
|
|
53
|
+
temp_df = df[df[label] == label_type].sort_values(by=x)
|
|
54
|
+
|
|
55
|
+
if style.format_funcs.get("label"):
|
|
56
|
+
label_type = style.format_funcs.get("label")(label_type)
|
|
57
|
+
if std:
|
|
58
|
+
ma = temp_df[y].rolling(window=7, min_periods=1).mean()
|
|
59
|
+
std_dev = temp_df[y].rolling(window=7, min_periods=1).std()
|
|
60
|
+
# Calculate the last moving average value to include in the legend
|
|
61
|
+
last_ma_value = ma.iloc[-1]
|
|
62
|
+
# Dynamically creating the legend label
|
|
63
|
+
label_str = f"{string_formatter(label_type)} (avg 7d: {style.format_funcs[y](last_ma_value)})"
|
|
64
|
+
# Plot moving average and include the last MA value in the label for the legend
|
|
65
|
+
ax.plot(temp_df.index, ma, color=color,
|
|
66
|
+
linestyle='--', label=label_str)
|
|
67
|
+
|
|
68
|
+
ax.fill_between(temp_df.index, ma - std_dev, ma +
|
|
69
|
+
std_dev, color=color, alpha=0.2, label='_nolegend_')
|
|
70
|
+
else:
|
|
71
|
+
label_str = f"{string_formatter(label_type)}"
|
|
72
|
+
# Plot moving average and include the last MA value in the label for the legend
|
|
73
|
+
ax.plot(temp_df.index, temp_df[y], color=color, label=label_str)
|
|
74
|
+
|
|
75
|
+
ax.legend(
|
|
76
|
+
title=label,
|
|
77
|
+
fontsize=style.font_size-4,
|
|
78
|
+
title_fontsize=style.font_size,
|
|
79
|
+
labelcolor='linecolor',
|
|
80
|
+
facecolor=style.background_color)
|
|
81
|
+
|
|
82
|
+
ax.set_xlabel(string_formatter(x), color=style.font_color)
|
|
83
|
+
if style.format_funcs.get("x"):
|
|
84
|
+
ax.xaxis.set_major_formatter(
|
|
85
|
+
DynamicFuncFormatter(style.format_funcs.get("x")))
|
|
86
|
+
ax.tick_params(axis='x', colors=style.font_color,
|
|
87
|
+
labelrotation=45, labelsize=style.font_size-4)
|
|
88
|
+
|
|
89
|
+
ax.set_ylabel(string_formatter(y), color=style.font_color)
|
|
90
|
+
if style.format_funcs.get("y"):
|
|
91
|
+
ax.yaxis.set_major_formatter(
|
|
92
|
+
DynamicFuncFormatter(style.format_funcs.get("y")))
|
|
93
|
+
ax.tick_params(axis='y', colors=style.font_color,
|
|
94
|
+
labelsize=style.font_size-4)
|
|
95
|
+
ax.set_facecolor(style.background_color)
|
|
96
|
+
ax.grid(True)
|
|
97
|
+
if title:
|
|
98
|
+
ax.set_title(title, color=style.font_color, fontsize=style.font_size+4)
|
|
99
|
+
return ax
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def plot_timeserie_fig(pd_df: pd.DataFrame,
|
|
103
|
+
label: str,
|
|
104
|
+
x: str,
|
|
105
|
+
y: str,
|
|
106
|
+
title: Optional[str] = None,
|
|
107
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
108
|
+
max_values: int = 100,
|
|
109
|
+
sort_by: Optional[str] = None,
|
|
110
|
+
ascending: bool = False,
|
|
111
|
+
std: bool = False,
|
|
112
|
+
figsize: Tuple[float, float] = (19.2, 10.8)) -> Figure:
|
|
113
|
+
fig = plt.figure(figsize=figsize)
|
|
114
|
+
fig.patch.set_facecolor(style.background_color)
|
|
115
|
+
ax = fig.add_subplot()
|
|
116
|
+
ax = plot_timeserie_ax(pd_df=pd_df,
|
|
117
|
+
label=label,
|
|
118
|
+
x=x,
|
|
119
|
+
y=y,
|
|
120
|
+
title=title,
|
|
121
|
+
style=style,
|
|
122
|
+
max_values=max_values,
|
|
123
|
+
std=std,
|
|
124
|
+
sort_by=sort_by,
|
|
125
|
+
ascending=ascending,
|
|
126
|
+
ax=ax)
|
|
127
|
+
return fig
|
|
128
|
+
# endregion
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
|
|
2
|
+
from .StyleTemplate import StyleTemplate
|
|
3
|
+
from .Bubble import plot_bubble_ax, plot_bubble_fig, BUBBLE_STYLE_TEMPLATE
|
|
4
|
+
from .Composite import plot_composite_bubble
|
|
5
|
+
from .Timeserie import plot_timeserie_ax, plot_timeserie_fig, TIMESERIE_STYLE_TEMPLATE
|
|
6
|
+
from .Table import plot_table_ax, plot_table_fig, TABLE_STYLE_TEMPLATE
|
|
7
|
+
from .Network import plot_network, plot_network_components, NETWORK_STYLE_TEMPLATE
|
|
8
|
+
from .Treemap import plot_treemap, TREEMAP_STYLE_TEMPLATE
|
|
9
|
+
from typing import List, Optional, Tuple
|
|
10
|
+
import pandas as pd
|
|
11
|
+
from pandas.api.extensions import register_dataframe_accessor
|
|
12
|
+
|
|
13
|
+
from matplotlib.axes import Axes
|
|
14
|
+
from matplotlib.figure import Figure
|
|
15
|
+
import plotly.graph_objects as go
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@register_dataframe_accessor("mpl")
|
|
19
|
+
class DataFrameAccessor:
|
|
20
|
+
|
|
21
|
+
def __init__(self, pd_df: pd.DataFrame):
|
|
22
|
+
self._obj = pd_df
|
|
23
|
+
|
|
24
|
+
def plot_bubble_ax(self,
|
|
25
|
+
label: str,
|
|
26
|
+
x: str,
|
|
27
|
+
y: str,
|
|
28
|
+
z: str,
|
|
29
|
+
title: Optional[str] = None,
|
|
30
|
+
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
31
|
+
max_values: int = 50,
|
|
32
|
+
center_to_mean: bool = False,
|
|
33
|
+
sort_by: Optional[str] = None,
|
|
34
|
+
ascending: bool = False,
|
|
35
|
+
hline: bool = False,
|
|
36
|
+
vline: bool = False,
|
|
37
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
38
|
+
|
|
39
|
+
return plot_bubble_ax(pd_df=self._obj,
|
|
40
|
+
label=label,
|
|
41
|
+
x=x,
|
|
42
|
+
y=y,
|
|
43
|
+
z=z,
|
|
44
|
+
title=title,
|
|
45
|
+
style=style,
|
|
46
|
+
max_values=max_values,
|
|
47
|
+
center_to_mean=center_to_mean,
|
|
48
|
+
sort_by=sort_by,
|
|
49
|
+
ascending=ascending,
|
|
50
|
+
hline=hline,
|
|
51
|
+
vline=vline,
|
|
52
|
+
ax=ax)
|
|
53
|
+
|
|
54
|
+
def plot_bubble_fig(self,
|
|
55
|
+
label: str,
|
|
56
|
+
x: str,
|
|
57
|
+
y: str,
|
|
58
|
+
z: str,
|
|
59
|
+
title: Optional[str] = None,
|
|
60
|
+
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
61
|
+
max_values: int = 50,
|
|
62
|
+
center_to_mean: bool = False,
|
|
63
|
+
sort_by: Optional[str] = None,
|
|
64
|
+
ascending: bool = False,
|
|
65
|
+
hline: bool = False,
|
|
66
|
+
vline: bool = False,
|
|
67
|
+
figsize: Tuple[float, float] = (19.2, 10.8)) -> Figure:
|
|
68
|
+
|
|
69
|
+
return plot_bubble_fig(pd_df=self._obj,
|
|
70
|
+
label=label,
|
|
71
|
+
x=x,
|
|
72
|
+
y=y,
|
|
73
|
+
z=z,
|
|
74
|
+
title=title,
|
|
75
|
+
style=style,
|
|
76
|
+
max_values=max_values,
|
|
77
|
+
center_to_mean=center_to_mean,
|
|
78
|
+
sort_by=sort_by,
|
|
79
|
+
ascending=ascending,
|
|
80
|
+
hline=hline,
|
|
81
|
+
vline=vline,
|
|
82
|
+
figsize=figsize)
|
|
83
|
+
|
|
84
|
+
def plot_composite_bubble(self,
|
|
85
|
+
label: str,
|
|
86
|
+
x: str,
|
|
87
|
+
y: str,
|
|
88
|
+
z: str,
|
|
89
|
+
title: Optional[str] = None,
|
|
90
|
+
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
91
|
+
max_values: int = 100,
|
|
92
|
+
center_to_mean: bool = False,
|
|
93
|
+
sort_by: Optional[str] = None,
|
|
94
|
+
ascending: bool = False,
|
|
95
|
+
ax: Optional[Axes] = None) -> Figure:
|
|
96
|
+
|
|
97
|
+
return plot_composite_bubble(pd_df=self._obj,
|
|
98
|
+
label=label,
|
|
99
|
+
x=x,
|
|
100
|
+
y=y,
|
|
101
|
+
z=z,
|
|
102
|
+
title=title,
|
|
103
|
+
style=style,
|
|
104
|
+
max_values=max_values,
|
|
105
|
+
center_to_mean=center_to_mean,
|
|
106
|
+
sort_by=sort_by,
|
|
107
|
+
ascending=ascending,
|
|
108
|
+
ax=ax)
|
|
109
|
+
|
|
110
|
+
def plot_table_ax(self,
|
|
111
|
+
cols: List[str],
|
|
112
|
+
title: Optional[str] = None,
|
|
113
|
+
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
114
|
+
max_values: int = 20,
|
|
115
|
+
sort_by: Optional[str] = None,
|
|
116
|
+
ascending: bool = False,
|
|
117
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
118
|
+
|
|
119
|
+
return plot_table_ax(pd_df=self._obj,
|
|
120
|
+
cols=cols,
|
|
121
|
+
title=title,
|
|
122
|
+
style=style,
|
|
123
|
+
max_values=max_values,
|
|
124
|
+
sort_by=sort_by,
|
|
125
|
+
ascending=ascending,
|
|
126
|
+
ax=ax)
|
|
127
|
+
|
|
128
|
+
def plot_table_fig(self,
|
|
129
|
+
cols: List[str],
|
|
130
|
+
title: Optional[str] = None,
|
|
131
|
+
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
132
|
+
max_values: int = 20,
|
|
133
|
+
sort_by: Optional[str] = None,
|
|
134
|
+
ascending: bool = False,
|
|
135
|
+
figsize: Tuple[float, float] = (19.2, 10.8)) -> Axes:
|
|
136
|
+
|
|
137
|
+
return plot_table_fig(pd_df=self._obj,
|
|
138
|
+
cols=cols,
|
|
139
|
+
title=title,
|
|
140
|
+
style=style,
|
|
141
|
+
max_values=max_values,
|
|
142
|
+
sort_by=sort_by,
|
|
143
|
+
ascending=ascending,
|
|
144
|
+
figsize=figsize)
|
|
145
|
+
|
|
146
|
+
def plot_timeserie_ax(self,
|
|
147
|
+
label: str,
|
|
148
|
+
x: str,
|
|
149
|
+
y: str,
|
|
150
|
+
title: Optional[str] = None,
|
|
151
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
152
|
+
max_values: int = 100,
|
|
153
|
+
sort_by: Optional[str] = None,
|
|
154
|
+
ascending: bool = False,
|
|
155
|
+
std: bool = False,
|
|
156
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
157
|
+
|
|
158
|
+
return plot_timeserie_ax(pd_df=self._obj,
|
|
159
|
+
label=label,
|
|
160
|
+
x=x,
|
|
161
|
+
y=y,
|
|
162
|
+
title=title,
|
|
163
|
+
style=style,
|
|
164
|
+
max_values=max_values,
|
|
165
|
+
sort_by=sort_by,
|
|
166
|
+
ascending=ascending,
|
|
167
|
+
std=std,
|
|
168
|
+
ax=ax)
|
|
169
|
+
|
|
170
|
+
def plot_timeserie_fig(self,
|
|
171
|
+
label: str,
|
|
172
|
+
x: str,
|
|
173
|
+
y: str,
|
|
174
|
+
title: Optional[str] = None,
|
|
175
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
176
|
+
max_values: int = 100,
|
|
177
|
+
sort_by: Optional[str] = None,
|
|
178
|
+
ascending: bool = False,
|
|
179
|
+
std: bool = False,
|
|
180
|
+
figsize: Tuple[float, float] = (19.2, 10.8)) -> Axes:
|
|
181
|
+
|
|
182
|
+
return plot_timeserie_fig(pd_df=self._obj,
|
|
183
|
+
label=label,
|
|
184
|
+
x=x,
|
|
185
|
+
y=y,
|
|
186
|
+
title=title,
|
|
187
|
+
style=style,
|
|
188
|
+
max_values=max_values,
|
|
189
|
+
sort_by=sort_by,
|
|
190
|
+
ascending=ascending,
|
|
191
|
+
std=std,
|
|
192
|
+
figsize=figsize)
|
|
193
|
+
|
|
194
|
+
def plot_network(self,
|
|
195
|
+
source: str = "source",
|
|
196
|
+
target: str = "target",
|
|
197
|
+
weight: str = "weight",
|
|
198
|
+
title: Optional[str] = None,
|
|
199
|
+
style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
|
|
200
|
+
sort_by: Optional[str] = None,
|
|
201
|
+
ascending: bool = False,
|
|
202
|
+
node_list: Optional[List] = None,
|
|
203
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
204
|
+
|
|
205
|
+
return plot_network(df=self._obj,
|
|
206
|
+
source=source,
|
|
207
|
+
target=target,
|
|
208
|
+
weight=weight,
|
|
209
|
+
title=title,
|
|
210
|
+
style=style,
|
|
211
|
+
sort_by=sort_by,
|
|
212
|
+
ascending=ascending,
|
|
213
|
+
node_list=node_list,
|
|
214
|
+
ax=ax)
|
|
215
|
+
|
|
216
|
+
def plot_network_components(self,
|
|
217
|
+
source: str = "source",
|
|
218
|
+
target: str = "target",
|
|
219
|
+
weight: str = "weight",
|
|
220
|
+
title: Optional[str] = None,
|
|
221
|
+
style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
|
|
222
|
+
sort_by: Optional[str] = None,
|
|
223
|
+
ascending: bool = False,
|
|
224
|
+
node_list: Optional[List] = None,
|
|
225
|
+
ax: Optional[Axes] = None) -> Axes:
|
|
226
|
+
|
|
227
|
+
return plot_network_components(df=self._obj,
|
|
228
|
+
source=source,
|
|
229
|
+
target=target,
|
|
230
|
+
weight=weight,
|
|
231
|
+
title=title,
|
|
232
|
+
style=style,
|
|
233
|
+
sort_by=sort_by,
|
|
234
|
+
ascending=ascending,
|
|
235
|
+
node_list=node_list,
|
|
236
|
+
ax=ax)
|
|
237
|
+
|
|
238
|
+
def plot_treemap(self,
|
|
239
|
+
path: str,
|
|
240
|
+
values: str,
|
|
241
|
+
style: StyleTemplate = TREEMAP_STYLE_TEMPLATE,
|
|
242
|
+
title: Optional[str] = None,
|
|
243
|
+
color: Optional[str] = None,
|
|
244
|
+
max_values: int = 100,
|
|
245
|
+
sort_by: Optional[str] = None,
|
|
246
|
+
ascending: bool = False) -> go.Figure:
|
|
247
|
+
return plot_treemap(pd_df=self._obj,
|
|
248
|
+
path=path,
|
|
249
|
+
values=values,
|
|
250
|
+
title=title,
|
|
251
|
+
style=style,
|
|
252
|
+
color=color,
|
|
253
|
+
max_values=max_values,
|
|
254
|
+
sort_by=sort_by,
|
|
255
|
+
ascending=ascending)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
__all__ = ["validate_dataframe", "plot_bubble_ax", "plot_timeserie_ax", "plot_table_ax", "plot_network", "plot_network_components",
|
|
259
|
+
"plot_pivotbar", "plot_treemap", "plot_composite_bubble", "StyleTemplate", "DataFrameAccessor"]
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
[project]
|
|
5
5
|
name = "MatplotLibAPI"
|
|
6
|
-
version="v3.2.
|
|
6
|
+
version="v3.2.2"
|
|
7
7
|
readme = "README.md"
|
|
8
8
|
requires-python=">=3.7"
|
|
9
9
|
dependencies = ["pandas","matplotlib","networkx","plotly","seaborn","scikit-learn","kaleido","nbformat"]
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# Hint for Visual Code Python Interactive window
|
|
2
|
-
# %%
|
|
3
|
-
from typing import Optional
|
|
4
|
-
import pandas as pd
|
|
5
|
-
import matplotlib.pyplot as plt
|
|
6
|
-
from matplotlib.axes import Axes
|
|
7
|
-
import seaborn as sns
|
|
8
|
-
|
|
9
|
-
from .StyleTemplate import DynamicFuncFormatter, StyleTemplate, string_formatter, bmk_formatter, format_func,validate_dataframe
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TIMESERIE_STYLE_TEMPLATE = StyleTemplate(
|
|
13
|
-
palette='rocket',
|
|
14
|
-
format_funcs={"y": bmk_formatter, "label": string_formatter}
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
# region Line
|
|
18
|
-
|
|
19
|
-
def plot_timeserie(pd_df: pd.DataFrame,
|
|
20
|
-
label: str,
|
|
21
|
-
x: str,
|
|
22
|
-
y: str,
|
|
23
|
-
title: Optional[str] = None,
|
|
24
|
-
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
25
|
-
max_values: int = 100,
|
|
26
|
-
sort_by: Optional[str] = None,
|
|
27
|
-
ascending: bool = False,
|
|
28
|
-
ax: Optional[Axes] = None) -> Axes:
|
|
29
|
-
|
|
30
|
-
validate_dataframe(pd_df, cols=[label, x, y], sort_by=sort_by)
|
|
31
|
-
style.format_funcs = format_func(style.format_funcs, label=label, x=x, y=y)
|
|
32
|
-
|
|
33
|
-
df = pd_df[[label, x, y]].sort_values(by=[label, x])
|
|
34
|
-
df[x] = pd.to_datetime(df[x])
|
|
35
|
-
df.set_index(x, inplace=True)
|
|
36
|
-
|
|
37
|
-
sns.set_palette(style.palette)
|
|
38
|
-
# Colors for each group
|
|
39
|
-
colors = sns.color_palette(n_colors=len(df.columns))
|
|
40
|
-
if ax is None:
|
|
41
|
-
ax = plt.gca()
|
|
42
|
-
|
|
43
|
-
# Get unique dimension_types
|
|
44
|
-
label_types = df[label].unique()
|
|
45
|
-
|
|
46
|
-
# Colors for each group
|
|
47
|
-
colors = sns.color_palette(n_colors=len(label_types))
|
|
48
|
-
|
|
49
|
-
for label_type, color in zip(label_types, colors):
|
|
50
|
-
temp_df = df[df[label] == label_type].sort_values(by=x)
|
|
51
|
-
|
|
52
|
-
if style.format_funcs.get("label"):
|
|
53
|
-
label_type = style.format_funcs.get("label")(label_type)
|
|
54
|
-
|
|
55
|
-
ma = temp_df[y].rolling(window=7, min_periods=1).mean()
|
|
56
|
-
std_dev = temp_df[y].rolling(window=7, min_periods=1).std()
|
|
57
|
-
|
|
58
|
-
# Calculate the last moving average value to include in the legend
|
|
59
|
-
last_ma_value = ma.iloc[-1]
|
|
60
|
-
|
|
61
|
-
# Dynamically creating the legend label
|
|
62
|
-
label_str = f"{string_formatter(label_type)} (avg 7d: {style.format_funcs[y](last_ma_value)})"
|
|
63
|
-
|
|
64
|
-
# Plot moving average and include the last MA value in the label for the legend
|
|
65
|
-
plt.plot(temp_df.index, ma, color=color,
|
|
66
|
-
linestyle='--', label=label_str)
|
|
67
|
-
plt.fill_between(temp_df.index, ma - std_dev, ma +
|
|
68
|
-
std_dev, color=color, alpha=0.2, label='_nolegend_')
|
|
69
|
-
|
|
70
|
-
ax.legend(
|
|
71
|
-
title=label,
|
|
72
|
-
fontsize=style.font_size-4,
|
|
73
|
-
title_fontsize=style.font_size,
|
|
74
|
-
labelcolor='linecolor',
|
|
75
|
-
facecolor=style.background_color)
|
|
76
|
-
|
|
77
|
-
ax.set_xlabel(string_formatter(x), color=style.font_color)
|
|
78
|
-
if style.format_funcs.get("x"):
|
|
79
|
-
ax.xaxis.set_major_formatter(
|
|
80
|
-
DynamicFuncFormatter(style.format_funcs.get("x")))
|
|
81
|
-
ax.tick_params(axis='x', colors=style.font_color,
|
|
82
|
-
labelrotation=45, labelsize=style.font_size-4)
|
|
83
|
-
|
|
84
|
-
ax.set_ylabel(string_formatter(y), color=style.font_color)
|
|
85
|
-
if style.format_funcs.get("y"):
|
|
86
|
-
ax.yaxis.set_major_formatter(
|
|
87
|
-
DynamicFuncFormatter(style.format_funcs.get("y")))
|
|
88
|
-
ax.tick_params(axis='y', colors=style.font_color,
|
|
89
|
-
labelsize=style.font_size-4)
|
|
90
|
-
ax.set_facecolor(style.background_color)
|
|
91
|
-
ax.grid(True)
|
|
92
|
-
if title:
|
|
93
|
-
ax.set_title(title, color=style.font_color, fontsize=style.font_size+4)
|
|
94
|
-
return ax
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# endregion
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
from .StyleTemplate import StyleTemplate
|
|
3
|
-
from .Bubble import plot_bubble, BUBBLE_STYLE_TEMPLATE
|
|
4
|
-
from .Composite import plot_composite_bubble
|
|
5
|
-
from .Timeserie import plot_timeserie, TIMESERIE_STYLE_TEMPLATE
|
|
6
|
-
from .Table import plot_table, TABLE_STYLE_TEMPLATE
|
|
7
|
-
from .Network import Graph
|
|
8
|
-
from .Treemap import plot_treemap, TREEMAP_STYLE_TEMPLATE
|
|
9
|
-
from typing import List, Optional
|
|
10
|
-
import pandas as pd
|
|
11
|
-
from pandas.api.extensions import register_dataframe_accessor
|
|
12
|
-
|
|
13
|
-
from matplotlib.axes import Axes
|
|
14
|
-
from matplotlib.figure import Figure
|
|
15
|
-
import plotly.graph_objects as go
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@register_dataframe_accessor("mpl")
|
|
22
|
-
class DataFrameAccessor:
|
|
23
|
-
|
|
24
|
-
def __init__(self, pd_df: pd.DataFrame):
|
|
25
|
-
self._obj = pd_df
|
|
26
|
-
|
|
27
|
-
def plot_bubble(self,
|
|
28
|
-
label: str,
|
|
29
|
-
x: str,
|
|
30
|
-
y: str,
|
|
31
|
-
z: str,
|
|
32
|
-
title: Optional[str] = None,
|
|
33
|
-
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
34
|
-
max_values: int = 50,
|
|
35
|
-
center_to_mean: bool = False,
|
|
36
|
-
sort_by: Optional[str] = None,
|
|
37
|
-
ascending: bool = False) -> Axes:
|
|
38
|
-
|
|
39
|
-
return plot_bubble(pd_df=self._obj,
|
|
40
|
-
label=label,
|
|
41
|
-
x=x,
|
|
42
|
-
y=y,
|
|
43
|
-
z=z,
|
|
44
|
-
title=title,
|
|
45
|
-
style=style,
|
|
46
|
-
max_values=max_values,
|
|
47
|
-
center_to_mean=center_to_mean,
|
|
48
|
-
sort_by=sort_by,
|
|
49
|
-
ascending=ascending)
|
|
50
|
-
|
|
51
|
-
def plot_composite_bubble(self,
|
|
52
|
-
label: str,
|
|
53
|
-
x: str,
|
|
54
|
-
y: str,
|
|
55
|
-
z: str,
|
|
56
|
-
title: Optional[str] = None,
|
|
57
|
-
style: StyleTemplate = BUBBLE_STYLE_TEMPLATE,
|
|
58
|
-
max_values: int = 100,
|
|
59
|
-
center_to_mean: bool = False,
|
|
60
|
-
sort_by: Optional[str] = None,
|
|
61
|
-
ascending: bool = False) -> Figure:
|
|
62
|
-
|
|
63
|
-
return plot_composite_bubble(pd_df=self._obj,
|
|
64
|
-
label=label,
|
|
65
|
-
x=x,
|
|
66
|
-
y=y,
|
|
67
|
-
z=z,
|
|
68
|
-
title=title,
|
|
69
|
-
style=style,
|
|
70
|
-
max_values=max_values,
|
|
71
|
-
center_to_mean=center_to_mean,
|
|
72
|
-
sort_by=sort_by,
|
|
73
|
-
ascending=ascending)
|
|
74
|
-
|
|
75
|
-
def plot_table(self,
|
|
76
|
-
cols: List[str],
|
|
77
|
-
title: Optional[str] = None,
|
|
78
|
-
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
79
|
-
max_values: int = 20,
|
|
80
|
-
sort_by: Optional[str] = None,
|
|
81
|
-
ascending: bool = False) -> Axes:
|
|
82
|
-
|
|
83
|
-
return plot_table(pd_df=self._obj,
|
|
84
|
-
cols=cols,
|
|
85
|
-
title=title,
|
|
86
|
-
style=style,
|
|
87
|
-
max_values=max_values,
|
|
88
|
-
sort_by=sort_by,
|
|
89
|
-
ascending=ascending)
|
|
90
|
-
|
|
91
|
-
def plot_timeserie(self,
|
|
92
|
-
label: str,
|
|
93
|
-
x: str,
|
|
94
|
-
y: str,
|
|
95
|
-
title: Optional[str] = None,
|
|
96
|
-
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
97
|
-
max_values: int = 100,
|
|
98
|
-
sort_by: Optional[str] = None,
|
|
99
|
-
ascending: bool = False) -> Axes:
|
|
100
|
-
|
|
101
|
-
return plot_timeserie(pd_df=self._obj,
|
|
102
|
-
label=label,
|
|
103
|
-
x=x,
|
|
104
|
-
y=y,
|
|
105
|
-
title=title,
|
|
106
|
-
style=style,
|
|
107
|
-
max_values=max_values,
|
|
108
|
-
sort_by=sort_by,
|
|
109
|
-
ascending=ascending)
|
|
110
|
-
|
|
111
|
-
def plot_network(self,
|
|
112
|
-
source: str = "source",
|
|
113
|
-
target: str = "target",
|
|
114
|
-
weight: str = "weight",
|
|
115
|
-
title: Optional[str] = None,
|
|
116
|
-
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
117
|
-
max_values: int = 20,
|
|
118
|
-
sort_by: Optional[str] = None,
|
|
119
|
-
ascending: bool = False) -> Axes:
|
|
120
|
-
|
|
121
|
-
graph = Graph.from_pandas_edgelist(df=self._obj,
|
|
122
|
-
source=source,
|
|
123
|
-
target=target,
|
|
124
|
-
weight=weight)
|
|
125
|
-
|
|
126
|
-
return graph.plotX(title, style)
|
|
127
|
-
|
|
128
|
-
def plot_treemap(self,
|
|
129
|
-
path: str,
|
|
130
|
-
values: str,
|
|
131
|
-
style: StyleTemplate = TREEMAP_STYLE_TEMPLATE,
|
|
132
|
-
title: Optional[str] = None,
|
|
133
|
-
color: Optional[str] = None,
|
|
134
|
-
max_values: int = 100,
|
|
135
|
-
sort_by: Optional[str] = None,
|
|
136
|
-
ascending: bool = False) -> go.Figure:
|
|
137
|
-
return plot_treemap(pd_df=self._obj,
|
|
138
|
-
path=path,
|
|
139
|
-
values=values,
|
|
140
|
-
title=title,
|
|
141
|
-
style=style,
|
|
142
|
-
color=color,
|
|
143
|
-
max_values=max_values,
|
|
144
|
-
sort_by=sort_by,
|
|
145
|
-
ascending=ascending)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
__all__ = ["validate_dataframe", "plot_bubble", "plot_timeserie", "plot_table", "plot_network", "plot_network_components",
|
|
149
|
-
"plot_pivotbar", "plot_treemap", "plot_composite_bubble", "StyleTemplate", "DataFrameAccessor"]
|
|
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
|
|
File without changes
|
|
File without changes
|