MatplotLibAPI 3.2.21__py3-none-any.whl → 4.0.0__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.
- MatplotLibAPI/__init__.py +4 -86
- MatplotLibAPI/accessor.py +519 -196
- MatplotLibAPI/area.py +177 -0
- MatplotLibAPI/bar.py +185 -0
- MatplotLibAPI/base_plot.py +88 -0
- MatplotLibAPI/box_violin.py +180 -0
- MatplotLibAPI/bubble.py +568 -0
- MatplotLibAPI/{Composite.py → composite.py} +127 -106
- MatplotLibAPI/heatmap.py +223 -0
- MatplotLibAPI/histogram.py +170 -0
- MatplotLibAPI/mcp/__init__.py +17 -0
- MatplotLibAPI/mcp/metadata.py +90 -0
- MatplotLibAPI/mcp/renderers.py +45 -0
- MatplotLibAPI/mcp_server.py +626 -0
- MatplotLibAPI/network/__init__.py +28 -0
- MatplotLibAPI/network/constants.py +22 -0
- MatplotLibAPI/network/core.py +1360 -0
- MatplotLibAPI/network/plot.py +597 -0
- MatplotLibAPI/network/scaling.py +56 -0
- MatplotLibAPI/pie.py +154 -0
- MatplotLibAPI/pivot.py +274 -0
- MatplotLibAPI/sankey.py +99 -0
- MatplotLibAPI/{StyleTemplate.py → style_template.py} +27 -22
- MatplotLibAPI/sunburst.py +139 -0
- MatplotLibAPI/{Table.py → table.py} +112 -87
- MatplotLibAPI/{Timeserie.py → timeserie.py} +98 -42
- MatplotLibAPI/{Treemap.py → treemap.py} +43 -55
- MatplotLibAPI/typing.py +12 -0
- MatplotLibAPI/{_visualization_utils.py → utils.py} +7 -13
- MatplotLibAPI/waffle.py +173 -0
- MatplotLibAPI/word_cloud.py +489 -0
- {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/METADATA +98 -9
- matplotlibapi-4.0.0.dist-info/RECORD +36 -0
- {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/WHEEL +1 -1
- matplotlibapi-4.0.0.dist-info/entry_points.txt +2 -0
- MatplotLibAPI/Area.py +0 -80
- MatplotLibAPI/Bar.py +0 -83
- MatplotLibAPI/BoxViolin.py +0 -75
- MatplotLibAPI/Bubble.py +0 -458
- MatplotLibAPI/Heatmap.py +0 -121
- MatplotLibAPI/Histogram.py +0 -73
- MatplotLibAPI/Network.py +0 -989
- MatplotLibAPI/Pie.py +0 -70
- MatplotLibAPI/Pivot.py +0 -134
- MatplotLibAPI/Sankey.py +0 -46
- MatplotLibAPI/Sunburst.py +0 -89
- MatplotLibAPI/Waffle.py +0 -86
- MatplotLibAPI/Wordcloud.py +0 -373
- MatplotLibAPI/_typing.py +0 -17
- matplotlibapi-3.2.21.dist-info/RECORD +0 -26
- {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -5,16 +5,24 @@ from typing import Dict, Iterable, Optional, Tuple, cast
|
|
|
5
5
|
import matplotlib.pyplot as plt
|
|
6
6
|
import pandas as pd
|
|
7
7
|
import plotly.graph_objects as go
|
|
8
|
+
from matplotlib.axes import Axes
|
|
8
9
|
from matplotlib.figure import Figure
|
|
9
10
|
from matplotlib.gridspec import GridSpec
|
|
10
11
|
from plotly.subplots import make_subplots
|
|
11
12
|
|
|
12
|
-
from .
|
|
13
|
-
|
|
14
|
-
from .
|
|
15
|
-
from .
|
|
16
|
-
from .
|
|
17
|
-
|
|
13
|
+
from .base_plot import BasePlot
|
|
14
|
+
|
|
15
|
+
from .bubble import BUBBLE_STYLE_TEMPLATE, FIG_SIZE, Bubble
|
|
16
|
+
from .network import aplot_network, NetworkGraph
|
|
17
|
+
from .style_template import (
|
|
18
|
+
MAX_RESULTS,
|
|
19
|
+
TITLE_SCALE_FACTOR,
|
|
20
|
+
StyleTemplate,
|
|
21
|
+
validate_dataframe,
|
|
22
|
+
)
|
|
23
|
+
from .table import aplot_table
|
|
24
|
+
from .treemap import TREEMAP_STYLE_TEMPLATE, aplot_treemap
|
|
25
|
+
from .word_cloud import WORDCLOUD_STYLE_TEMPLATE, aplot_wordcloud, WordCloud
|
|
18
26
|
|
|
19
27
|
|
|
20
28
|
def plot_composite_bubble(
|
|
@@ -73,36 +81,29 @@ def plot_composite_bubble(
|
|
|
73
81
|
"""
|
|
74
82
|
validate_dataframe(pd_df, cols=[label, x, y, z], sort_by=sort_by)
|
|
75
83
|
|
|
76
|
-
if not sort_by:
|
|
77
|
-
sort_by = z
|
|
78
|
-
if not filter_by:
|
|
79
|
-
filter_by = z
|
|
80
|
-
plot_df = pd_df.sort_values(by=filter_by, ascending=ascending)[
|
|
81
|
-
[label, x, y, z]
|
|
82
|
-
].head(max_values)
|
|
83
|
-
|
|
84
84
|
fig = cast(Figure, plt.figure(figsize=figsize))
|
|
85
|
-
fig.
|
|
85
|
+
fig.set_facecolor(style.background_color)
|
|
86
86
|
grid = GridSpec(2, 2, height_ratios=[2, 1], width_ratios=[1, 1])
|
|
87
87
|
ax = fig.add_subplot(grid[0, 0:])
|
|
88
|
-
ax =
|
|
89
|
-
pd_df=
|
|
88
|
+
ax = Bubble(
|
|
89
|
+
pd_df=pd_df,
|
|
90
90
|
label=label,
|
|
91
91
|
x=x,
|
|
92
92
|
y=y,
|
|
93
93
|
z=z,
|
|
94
|
-
title=title,
|
|
95
|
-
style=style,
|
|
96
94
|
max_values=max_values,
|
|
97
95
|
center_to_mean=center_to_mean,
|
|
98
96
|
sort_by=sort_by,
|
|
99
97
|
ascending=ascending,
|
|
98
|
+
).aplot(
|
|
99
|
+
title=title,
|
|
100
|
+
style=style,
|
|
100
101
|
ax=ax,
|
|
101
102
|
)
|
|
102
103
|
|
|
103
104
|
ax2 = fig.add_subplot(grid[1, 0])
|
|
104
105
|
ax2 = aplot_table(
|
|
105
|
-
pd_df=
|
|
106
|
+
pd_df=pd_df,
|
|
106
107
|
cols=[label, z, y, x],
|
|
107
108
|
title=f"Top {table_rows}",
|
|
108
109
|
ax=ax2,
|
|
@@ -113,7 +114,7 @@ def plot_composite_bubble(
|
|
|
113
114
|
)
|
|
114
115
|
ax3 = fig.add_subplot(grid[1, 1])
|
|
115
116
|
ax3 = aplot_table(
|
|
116
|
-
pd_df=
|
|
117
|
+
pd_df=pd_df,
|
|
117
118
|
cols=[label, z, y, x],
|
|
118
119
|
title=f"Last {table_rows}",
|
|
119
120
|
ax=ax3,
|
|
@@ -122,7 +123,10 @@ def plot_composite_bubble(
|
|
|
122
123
|
max_values=table_rows,
|
|
123
124
|
style=style,
|
|
124
125
|
)
|
|
125
|
-
|
|
126
|
+
if title:
|
|
127
|
+
fig.tight_layout(rect=(0, 0, 1, 0.95))
|
|
128
|
+
else:
|
|
129
|
+
fig.tight_layout()
|
|
126
130
|
return fig
|
|
127
131
|
|
|
128
132
|
|
|
@@ -162,90 +166,78 @@ def plot_composite_treemap(
|
|
|
162
166
|
go.Figure, optional
|
|
163
167
|
Composite treemap figure, or None if no data frames are provided.
|
|
164
168
|
"""
|
|
169
|
+
go_fig = go.Figure()
|
|
165
170
|
num_dimensions = len(pd_dfs)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
subplot_titles=subplot_titles,
|
|
179
|
-
vertical_spacing=0.2,
|
|
180
|
-
)
|
|
171
|
+
subplot_titles = [
|
|
172
|
+
f"{title}::{dim.title()}" if title is not None else dim.title()
|
|
173
|
+
for dim in pd_dfs
|
|
174
|
+
]
|
|
175
|
+
fig = make_subplots(
|
|
176
|
+
rows=num_dimensions,
|
|
177
|
+
cols=1,
|
|
178
|
+
specs=[[{"type": "treemap"} for _ in range(1)] for _ in range(num_dimensions)],
|
|
179
|
+
subplot_titles=subplot_titles,
|
|
180
|
+
vertical_spacing=0.2,
|
|
181
|
+
figure=go_fig,
|
|
182
|
+
)
|
|
181
183
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
current_row += 1
|
|
196
|
-
return fig
|
|
197
|
-
return None
|
|
184
|
+
for current_row, (path, df) in enumerate(pd_dfs.items(), start=1):
|
|
185
|
+
trm = aplot_treemap(
|
|
186
|
+
pd_df=df,
|
|
187
|
+
path=path,
|
|
188
|
+
values=values,
|
|
189
|
+
style=style,
|
|
190
|
+
color=color,
|
|
191
|
+
sort_by=sort_by,
|
|
192
|
+
ascending=ascending,
|
|
193
|
+
max_values=max_values,
|
|
194
|
+
)
|
|
195
|
+
fig.add_trace(trm, row=current_row, col=1)
|
|
196
|
+
return fig
|
|
198
197
|
|
|
199
198
|
|
|
200
|
-
def
|
|
201
|
-
|
|
199
|
+
def fplot_wordcloud_network(
|
|
200
|
+
node_df: pd.DataFrame,
|
|
202
201
|
edges_df: pd.DataFrame,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
target: str = "target",
|
|
207
|
-
edge_weight: str = "weight",
|
|
208
|
-
wordcloud_title: Optional[str] = None,
|
|
209
|
-
network_title: Optional[str] = None,
|
|
210
|
-
wordcloud_style: StyleTemplate = WORDCLOUD_STYLE_TEMPLATE,
|
|
211
|
-
network_style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
|
|
202
|
+
edge_source_col: str = "source",
|
|
203
|
+
edge_target_col: str = "target",
|
|
204
|
+
edge_weight_col: str = "weight",
|
|
212
205
|
max_words: int = MAX_RESULTS,
|
|
213
206
|
stopwords: Optional[Iterable[str]] = None,
|
|
207
|
+
title: Optional[str] = None,
|
|
208
|
+
style: StyleTemplate = WORDCLOUD_STYLE_TEMPLATE,
|
|
209
|
+
wordcloud_style: Optional[StyleTemplate] = None,
|
|
210
|
+
network_style: Optional[StyleTemplate] = None,
|
|
214
211
|
figsize: Tuple[float, float] = FIG_SIZE,
|
|
215
212
|
) -> Figure:
|
|
216
213
|
"""Plot a word cloud above a network graph.
|
|
217
214
|
|
|
218
215
|
Parameters
|
|
219
216
|
----------
|
|
220
|
-
nodes_df : pd.DataFrame
|
|
221
|
-
DataFrame containing node labels and optional weights for the word cloud.
|
|
222
217
|
edges_df : pd.DataFrame
|
|
223
218
|
DataFrame containing edge connections for the network plot.
|
|
224
|
-
|
|
225
|
-
Column in ``nodes_df`` containing the node labels. The default is ``"node"``.
|
|
226
|
-
node_weight : str, optional
|
|
227
|
-
Column in ``nodes_df`` containing weights for sizing words. The default is
|
|
228
|
-
``"weight"``.
|
|
229
|
-
source : str, optional
|
|
219
|
+
edge_source_col : str, optional
|
|
230
220
|
Column in ``edges_df`` containing source nodes. The default is ``"source"``.
|
|
231
|
-
|
|
221
|
+
edge_target_col : str, optional
|
|
232
222
|
Column in ``edges_df`` containing target nodes. The default is ``"target"``.
|
|
233
|
-
|
|
223
|
+
edge_weight_col : str, optional
|
|
234
224
|
Column in ``edges_df`` containing edge weights. The default is ``"weight"``.
|
|
235
|
-
wordcloud_title : str, optional
|
|
236
|
-
Title for the word cloud subplot. The default is ``None``.
|
|
237
|
-
network_title : str, optional
|
|
238
|
-
Title for the network subplot. The default is ``None``.
|
|
239
|
-
wordcloud_style : StyleTemplate, optional
|
|
240
|
-
Style configuration for the word cloud. The default is
|
|
241
|
-
``WORDCLOUD_STYLE_TEMPLATE``.
|
|
242
|
-
network_style : StyleTemplate, optional
|
|
243
|
-
Style configuration for the network graph. The default is
|
|
244
|
-
``NETWORK_STYLE_TEMPLATE``.
|
|
245
225
|
max_words : int, optional
|
|
246
226
|
Maximum number of words to include in the word cloud. The default is ``50``.
|
|
247
227
|
stopwords : Iterable[str], optional
|
|
248
228
|
Stopwords to exclude from the word cloud. The default is ``None``.
|
|
229
|
+
title : str, optional
|
|
230
|
+
Title for the composite figure. The default is ``None``.
|
|
231
|
+
style : StyleTemplate, optional
|
|
232
|
+
Shared style configuration applied to the composite figure and used for
|
|
233
|
+
subplots when specialized styles are not provided. The default is
|
|
234
|
+
``WORDCLOUD_STYLE_TEMPLATE``.
|
|
235
|
+
wordcloud_style : StyleTemplate, optional
|
|
236
|
+
Optional style configuration for the word cloud subplot. When ``None``
|
|
237
|
+
the shared ``style`` is used. The default is ``None``.
|
|
238
|
+
network_style : StyleTemplate, optional
|
|
239
|
+
Optional style configuration for the network subplot. When ``None`` the
|
|
240
|
+
shared ``style`` is used. The default is ``None``.
|
|
249
241
|
figsize : tuple[float, float], optional
|
|
250
242
|
Size of the composite figure. The default is ``FIG_SIZE``.
|
|
251
243
|
|
|
@@ -254,35 +246,64 @@ def plot_wordcloud_network(
|
|
|
254
246
|
Figure
|
|
255
247
|
Matplotlib figure containing the word cloud on top and network below.
|
|
256
248
|
"""
|
|
257
|
-
|
|
258
|
-
|
|
249
|
+
fig_raw, axes_raw = plt.subplots(
|
|
250
|
+
2,
|
|
251
|
+
1,
|
|
252
|
+
figsize=figsize,
|
|
253
|
+
gridspec_kw={"height_ratios": [1, 2]},
|
|
254
|
+
)
|
|
255
|
+
fig = cast(Figure, fig_raw)
|
|
256
|
+
wordcloud_ax, network_ax = cast(Tuple[Axes, Axes], axes_raw)
|
|
259
257
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
wordcloud_style = wordcloud_style or style
|
|
259
|
+
network_style = network_style or style
|
|
260
|
+
|
|
261
|
+
fig.set_facecolor(style.background_color)
|
|
262
|
+
if title:
|
|
263
|
+
fig.suptitle(
|
|
264
|
+
title,
|
|
265
|
+
color=style.font_color,
|
|
266
|
+
fontsize=style.font_size * TITLE_SCALE_FACTOR,
|
|
267
|
+
fontname=style.font_name,
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
validate_dataframe(
|
|
271
|
+
node_df,
|
|
272
|
+
cols=["node", "weight"],
|
|
273
|
+
)
|
|
274
|
+
validate_dataframe(
|
|
275
|
+
edges_df,
|
|
276
|
+
cols=[edge_source_col, edge_target_col, edge_weight_col],
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
network = NetworkGraph.from_pandas(
|
|
280
|
+
node_df,
|
|
281
|
+
edges_df,
|
|
282
|
+
node_col="node",
|
|
283
|
+
node_weight_col="weight",
|
|
284
|
+
edge_source_col=edge_source_col,
|
|
285
|
+
edge_target_col=edge_target_col,
|
|
286
|
+
edge_weight_col=edge_weight_col,
|
|
287
|
+
)
|
|
288
|
+
network.aplot(
|
|
289
|
+
title=None,
|
|
290
|
+
style=network_style,
|
|
291
|
+
ax=network_ax,
|
|
292
|
+
)
|
|
263
293
|
|
|
264
|
-
wordcloud_ax = fig.add_subplot(grid[0, 0])
|
|
265
294
|
aplot_wordcloud(
|
|
266
|
-
pd_df=
|
|
267
|
-
text_column=
|
|
268
|
-
weight_column=
|
|
269
|
-
title=
|
|
295
|
+
pd_df=network.node_view.to_dataframe(),
|
|
296
|
+
text_column="node",
|
|
297
|
+
weight_column=edge_weight_col,
|
|
298
|
+
title=None,
|
|
270
299
|
style=wordcloud_style,
|
|
271
300
|
max_words=max_words,
|
|
272
301
|
stopwords=stopwords,
|
|
273
302
|
ax=wordcloud_ax,
|
|
274
303
|
)
|
|
275
304
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
target=target,
|
|
281
|
-
weight=edge_weight,
|
|
282
|
-
title=network_title,
|
|
283
|
-
style=network_style,
|
|
284
|
-
ax=network_ax,
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
fig.tight_layout()
|
|
305
|
+
if title:
|
|
306
|
+
fig.tight_layout(rect=(0, 0, 1, 0.95))
|
|
307
|
+
else:
|
|
308
|
+
fig.tight_layout()
|
|
288
309
|
return fig
|
MatplotLibAPI/heatmap.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Heatmap and correlation matrix helpers."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Optional, Sequence, Tuple
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from pandas.api.extensions import register_dataframe_accessor
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
import seaborn as sns
|
|
9
|
+
from matplotlib.axes import Axes
|
|
10
|
+
from matplotlib.figure import Figure
|
|
11
|
+
|
|
12
|
+
from .base_plot import BasePlot
|
|
13
|
+
|
|
14
|
+
from .style_template import (
|
|
15
|
+
HEATMAP_STYLE_TEMPLATE,
|
|
16
|
+
StyleTemplate,
|
|
17
|
+
string_formatter,
|
|
18
|
+
validate_dataframe,
|
|
19
|
+
)
|
|
20
|
+
from .utils import _get_axis
|
|
21
|
+
from .typing import CorrelationMethod
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"HEATMAP_STYLE_TEMPLATE",
|
|
25
|
+
"aplot_heatmap",
|
|
26
|
+
"aplot_correlation_matrix",
|
|
27
|
+
"fplot_heatmap",
|
|
28
|
+
"fplot_correlation_matrix",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@register_dataframe_accessor("heatmap")
|
|
33
|
+
class Heatmap(BasePlot):
|
|
34
|
+
"""Class for plotting heatmaps and correlation matrices."""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
pd_df: pd.DataFrame,
|
|
39
|
+
x: str,
|
|
40
|
+
y: str,
|
|
41
|
+
value: str,
|
|
42
|
+
):
|
|
43
|
+
self._obj = _prepare_data(pd_df, x, y, value)
|
|
44
|
+
self.x = x
|
|
45
|
+
self.y = y
|
|
46
|
+
self.value = value
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def correlation_matrix(self) -> pd.DataFrame:
|
|
50
|
+
"""Compute the correlation matrix for the underlying DataFrame."""
|
|
51
|
+
return self._obj.corr()
|
|
52
|
+
|
|
53
|
+
def aplot(
|
|
54
|
+
self,
|
|
55
|
+
title: Optional[str] = None,
|
|
56
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
57
|
+
ax: Optional[Axes] = None,
|
|
58
|
+
**kwargs: Any,
|
|
59
|
+
) -> Axes:
|
|
60
|
+
plot_ax = _get_axis(ax)
|
|
61
|
+
sns.heatmap(self._obj, cmap=style.palette, ax=plot_ax)
|
|
62
|
+
|
|
63
|
+
plot_ax.set_xlabel(string_formatter(self.x))
|
|
64
|
+
plot_ax.set_ylabel(string_formatter(self.y))
|
|
65
|
+
if title:
|
|
66
|
+
plot_ax.set_title(title)
|
|
67
|
+
return plot_ax
|
|
68
|
+
|
|
69
|
+
def fplot(
|
|
70
|
+
self,
|
|
71
|
+
title: Optional[str] = None,
|
|
72
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
73
|
+
figsize: Tuple[float, float] = (10, 6),
|
|
74
|
+
) -> Figure:
|
|
75
|
+
fig = Figure(
|
|
76
|
+
figsize=figsize,
|
|
77
|
+
facecolor=style.background_color,
|
|
78
|
+
edgecolor=style.background_color,
|
|
79
|
+
)
|
|
80
|
+
ax = Axes(fig=fig, facecolor=style.background_color)
|
|
81
|
+
self.aplot(title=title, style=style, ax=ax)
|
|
82
|
+
return fig
|
|
83
|
+
|
|
84
|
+
def aplot_correlation_matrix(
|
|
85
|
+
self,
|
|
86
|
+
title: Optional[str] = None,
|
|
87
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
88
|
+
ax: Optional[Axes] = None,
|
|
89
|
+
**kwargs: Any,
|
|
90
|
+
) -> Axes:
|
|
91
|
+
plot_ax = _get_axis(ax)
|
|
92
|
+
sns.heatmap(
|
|
93
|
+
self.correlation_matrix,
|
|
94
|
+
cmap=style.palette,
|
|
95
|
+
annot=True,
|
|
96
|
+
fmt=".2f",
|
|
97
|
+
ax=plot_ax,
|
|
98
|
+
)
|
|
99
|
+
if title:
|
|
100
|
+
plot_ax.set_title(title)
|
|
101
|
+
return plot_ax
|
|
102
|
+
|
|
103
|
+
def fplot_correlation_matrix(
|
|
104
|
+
self,
|
|
105
|
+
title: Optional[str] = None,
|
|
106
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
107
|
+
figsize: Tuple[float, float] = (10, 6),
|
|
108
|
+
) -> Figure:
|
|
109
|
+
fig = Figure(
|
|
110
|
+
figsize=figsize,
|
|
111
|
+
facecolor=style.background_color,
|
|
112
|
+
edgecolor=style.background_color,
|
|
113
|
+
)
|
|
114
|
+
ax = Axes(fig=fig, facecolor=style.background_color)
|
|
115
|
+
self.aplot(
|
|
116
|
+
title=title,
|
|
117
|
+
style=style,
|
|
118
|
+
ax=ax,
|
|
119
|
+
)
|
|
120
|
+
return fig
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _prepare_data(
|
|
124
|
+
pd_df: pd.DataFrame,
|
|
125
|
+
x: str,
|
|
126
|
+
y: str,
|
|
127
|
+
value: str,
|
|
128
|
+
) -> pd.DataFrame:
|
|
129
|
+
"""Prepare data for treemap plotting."""
|
|
130
|
+
validate_dataframe(pd_df, cols=[x, y, value])
|
|
131
|
+
plot_df = pd_df[[x, y, value]].pivot_table(
|
|
132
|
+
index=y, columns=x, values=value, aggfunc="mean"
|
|
133
|
+
)
|
|
134
|
+
return plot_df
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def aplot_heatmap(
|
|
138
|
+
pd_df: pd.DataFrame,
|
|
139
|
+
x: str,
|
|
140
|
+
y: str,
|
|
141
|
+
value: str,
|
|
142
|
+
title: Optional[str] = None,
|
|
143
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
144
|
+
ax: Optional[Axes] = None,
|
|
145
|
+
**kwargs: Any,
|
|
146
|
+
) -> Axes:
|
|
147
|
+
"""Plot a matrix heatmap for multivariate pattern detection."""
|
|
148
|
+
return Heatmap(
|
|
149
|
+
pd_df=pd_df,
|
|
150
|
+
x=x,
|
|
151
|
+
y=y,
|
|
152
|
+
value=value,
|
|
153
|
+
).aplot(
|
|
154
|
+
title=title,
|
|
155
|
+
style=style,
|
|
156
|
+
ax=ax,
|
|
157
|
+
**kwargs,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def aplot_correlation_matrix(
|
|
162
|
+
pd_df: pd.DataFrame,
|
|
163
|
+
columns: Optional[Sequence[str]] = None,
|
|
164
|
+
method: CorrelationMethod = "pearson",
|
|
165
|
+
title: Optional[str] = None,
|
|
166
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
167
|
+
ax: Optional[Axes] = None,
|
|
168
|
+
**kwargs: Any,
|
|
169
|
+
) -> Axes:
|
|
170
|
+
"""Plot a correlation matrix heatmap for numeric columns."""
|
|
171
|
+
return Heatmap(
|
|
172
|
+
pd_df=pd_df,
|
|
173
|
+
x="", # Placeholder since correlation matrix is square
|
|
174
|
+
y="", # Placeholder since correlation matrix is square
|
|
175
|
+
value="", # Placeholder since correlation matrix is computed internally
|
|
176
|
+
).aplot_correlation_matrix(
|
|
177
|
+
method=method,
|
|
178
|
+
title=title,
|
|
179
|
+
style=style,
|
|
180
|
+
ax=ax,
|
|
181
|
+
columns=columns,
|
|
182
|
+
**kwargs,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def fplot_heatmap(
|
|
187
|
+
pd_df: pd.DataFrame,
|
|
188
|
+
x: str,
|
|
189
|
+
y: str,
|
|
190
|
+
value: str,
|
|
191
|
+
title: Optional[str] = None,
|
|
192
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
193
|
+
figsize: Tuple[float, float] = (10, 6),
|
|
194
|
+
) -> Figure:
|
|
195
|
+
"""Plot a matrix heatmap on a new figure."""
|
|
196
|
+
return Heatmap(
|
|
197
|
+
pd_df=pd_df,
|
|
198
|
+
x=x,
|
|
199
|
+
y=y,
|
|
200
|
+
value=value,
|
|
201
|
+
).fplot(
|
|
202
|
+
title=title,
|
|
203
|
+
style=style,
|
|
204
|
+
figsize=figsize,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def fplot_correlation_matrix(
|
|
209
|
+
pd_df: pd.DataFrame,
|
|
210
|
+
x: str,
|
|
211
|
+
y: str,
|
|
212
|
+
value: str,
|
|
213
|
+
title: Optional[str] = None,
|
|
214
|
+
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
215
|
+
figsize: Tuple[float, float] = (10, 6),
|
|
216
|
+
) -> Figure:
|
|
217
|
+
"""Plot a correlation matrix heatmap on a new figure."""
|
|
218
|
+
return Heatmap(
|
|
219
|
+
pd_df=pd_df,
|
|
220
|
+
x=x, # Placeholder since correlation matrix is square
|
|
221
|
+
y=y, # Placeholder since correlation matrix is square
|
|
222
|
+
value=value, # Placeholder since correlation matrix is computed internally
|
|
223
|
+
).fplot_correlation_matrix(title=title, style=style, figsize=figsize)
|