MatplotLibAPI 4.0.1__py3-none-any.whl → 4.0.3__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 +3 -4
- MatplotLibAPI/accessor.py +146 -545
- MatplotLibAPI/area.py +7 -38
- MatplotLibAPI/bar.py +3 -38
- MatplotLibAPI/base_plot.py +102 -21
- MatplotLibAPI/box_violin.py +5 -41
- MatplotLibAPI/bubble.py +31 -109
- MatplotLibAPI/composite.py +237 -17
- MatplotLibAPI/heatmap.py +72 -60
- MatplotLibAPI/histogram.py +2 -26
- MatplotLibAPI/network/__init__.py +2 -0
- MatplotLibAPI/network/constants.py +1 -0
- MatplotLibAPI/network/core.py +45 -56
- MatplotLibAPI/network/plot.py +95 -6
- MatplotLibAPI/pie.py +2 -39
- MatplotLibAPI/pivot.py +9 -34
- MatplotLibAPI/table.py +1 -29
- MatplotLibAPI/timeserie.py +2 -30
- MatplotLibAPI/treemap.py +3 -1
- MatplotLibAPI/types.py +6 -0
- MatplotLibAPI/waffle.py +1 -43
- MatplotLibAPI/word_cloud.py +5 -57
- {matplotlibapi-4.0.1.dist-info → matplotlibapi-4.0.3.dist-info}/METADATA +5 -5
- matplotlibapi-4.0.3.dist-info/RECORD +35 -0
- MatplotLibAPI/typing.py +0 -12
- MatplotLibAPI/utils.py +0 -85
- matplotlibapi-4.0.1.dist-info/RECORD +0 -36
- {matplotlibapi-4.0.1.dist-info → matplotlibapi-4.0.3.dist-info}/WHEEL +0 -0
- {matplotlibapi-4.0.1.dist-info → matplotlibapi-4.0.3.dist-info}/entry_points.txt +0 -0
- {matplotlibapi-4.0.1.dist-info → matplotlibapi-4.0.3.dist-info}/licenses/LICENSE +0 -0
MatplotLibAPI/composite.py
CHANGED
|
@@ -7,13 +7,12 @@ import pandas as pd
|
|
|
7
7
|
import plotly.graph_objects as go
|
|
8
8
|
from matplotlib.axes import Axes
|
|
9
9
|
from matplotlib.figure import Figure
|
|
10
|
-
from matplotlib.gridspec import GridSpec
|
|
11
10
|
from plotly.subplots import make_subplots
|
|
12
11
|
|
|
13
|
-
from .base_plot import
|
|
12
|
+
from .base_plot import FIG_SIZE
|
|
14
13
|
|
|
15
|
-
from .bubble import
|
|
16
|
-
from .network import
|
|
14
|
+
from .bubble import aplot_bubble, Bubble
|
|
15
|
+
from .network import NetworkGraph
|
|
17
16
|
from .style_template import (
|
|
18
17
|
MAX_RESULTS,
|
|
19
18
|
TITLE_SCALE_FACTOR,
|
|
@@ -21,8 +20,8 @@ from .style_template import (
|
|
|
21
20
|
validate_dataframe,
|
|
22
21
|
)
|
|
23
22
|
from .table import aplot_table
|
|
24
|
-
from .treemap import
|
|
25
|
-
from .word_cloud import WORDCLOUD_STYLE_TEMPLATE, aplot_wordcloud
|
|
23
|
+
from .treemap import aplot_treemap
|
|
24
|
+
from .word_cloud import WORDCLOUD_STYLE_TEMPLATE, aplot_wordcloud
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
def plot_composite_bubble(
|
|
@@ -32,7 +31,7 @@ def plot_composite_bubble(
|
|
|
32
31
|
y: str,
|
|
33
32
|
z: str,
|
|
34
33
|
title: Optional[str] = None,
|
|
35
|
-
style: StyleTemplate =
|
|
34
|
+
style: Optional[StyleTemplate] = None,
|
|
36
35
|
max_values: int = 50,
|
|
37
36
|
center_to_mean: bool = False,
|
|
38
37
|
filter_by: Optional[str] = None,
|
|
@@ -80,12 +79,20 @@ def plot_composite_bubble(
|
|
|
80
79
|
Matplotlib figure containing the composite bubble chart and tables.
|
|
81
80
|
"""
|
|
82
81
|
validate_dataframe(pd_df, cols=[label, x, y, z], sort_by=sort_by)
|
|
82
|
+
if style is None:
|
|
83
|
+
style = WORDCLOUD_STYLE_TEMPLATE
|
|
84
|
+
fig = plt.figure(figsize=figsize)
|
|
85
|
+
gs = fig.add_gridspec(
|
|
86
|
+
2,
|
|
87
|
+
2,
|
|
88
|
+
height_ratios=[2, 1],
|
|
89
|
+
width_ratios=[1, 1],
|
|
90
|
+
)
|
|
91
|
+
ax = fig.add_subplot(gs[0, :])
|
|
92
|
+
ax2 = fig.add_subplot(gs[1, 0])
|
|
93
|
+
ax3 = fig.add_subplot(gs[1, 1])
|
|
83
94
|
|
|
84
|
-
|
|
85
|
-
fig.set_facecolor(style.background_color)
|
|
86
|
-
grid = GridSpec(2, 2, height_ratios=[2, 1], width_ratios=[1, 1])
|
|
87
|
-
ax = fig.add_subplot(grid[0, 0:])
|
|
88
|
-
ax = Bubble(
|
|
95
|
+
aplot_bubble(
|
|
89
96
|
pd_df=pd_df,
|
|
90
97
|
label=label,
|
|
91
98
|
x=x,
|
|
@@ -95,13 +102,11 @@ def plot_composite_bubble(
|
|
|
95
102
|
center_to_mean=center_to_mean,
|
|
96
103
|
sort_by=sort_by,
|
|
97
104
|
ascending=ascending,
|
|
98
|
-
).aplot(
|
|
99
105
|
title=title,
|
|
100
106
|
style=style,
|
|
101
107
|
ax=ax,
|
|
102
108
|
)
|
|
103
109
|
|
|
104
|
-
ax2 = fig.add_subplot(grid[1, 0])
|
|
105
110
|
ax2 = aplot_table(
|
|
106
111
|
pd_df=pd_df,
|
|
107
112
|
cols=[label, z, y, x],
|
|
@@ -112,7 +117,7 @@ def plot_composite_bubble(
|
|
|
112
117
|
max_values=table_rows,
|
|
113
118
|
style=style,
|
|
114
119
|
)
|
|
115
|
-
|
|
120
|
+
|
|
116
121
|
ax3 = aplot_table(
|
|
117
122
|
pd_df=pd_df,
|
|
118
123
|
cols=[label, z, y, x],
|
|
@@ -133,7 +138,7 @@ def plot_composite_bubble(
|
|
|
133
138
|
def plot_composite_treemap(
|
|
134
139
|
pd_dfs: Dict[str, pd.DataFrame],
|
|
135
140
|
values: str,
|
|
136
|
-
style: StyleTemplate =
|
|
141
|
+
style: Optional[StyleTemplate] = None,
|
|
137
142
|
title: Optional[str] = None,
|
|
138
143
|
color: Optional[str] = None,
|
|
139
144
|
sort_by: Optional[str] = None,
|
|
@@ -196,6 +201,219 @@ def plot_composite_treemap(
|
|
|
196
201
|
return fig
|
|
197
202
|
|
|
198
203
|
|
|
204
|
+
def fplot_bubble(
|
|
205
|
+
pd_df: pd.DataFrame,
|
|
206
|
+
label: str,
|
|
207
|
+
x: str,
|
|
208
|
+
y: str,
|
|
209
|
+
z: str,
|
|
210
|
+
title: Optional[str] = None,
|
|
211
|
+
style: Optional[StyleTemplate] = None,
|
|
212
|
+
max_values: int = 50,
|
|
213
|
+
center_to_mean: bool = False,
|
|
214
|
+
filter_by: Optional[str] = None,
|
|
215
|
+
sort_by: Optional[str] = None,
|
|
216
|
+
ascending: bool = False,
|
|
217
|
+
table_rows: int = 10,
|
|
218
|
+
figsize: Tuple[float, float] = FIG_SIZE,
|
|
219
|
+
) -> Figure:
|
|
220
|
+
"""Plot a composite bubble chart with summary tables.
|
|
221
|
+
|
|
222
|
+
Parameters
|
|
223
|
+
----------
|
|
224
|
+
pd_df : pd.DataFrame
|
|
225
|
+
Data to be plotted.
|
|
226
|
+
label : str
|
|
227
|
+
Column name for bubble labels.
|
|
228
|
+
x : str
|
|
229
|
+
Column name for the x-axis values.
|
|
230
|
+
y : str
|
|
231
|
+
Column name for the y-axis values.
|
|
232
|
+
z : str
|
|
233
|
+
Column name for bubble sizes.
|
|
234
|
+
title : str, optional
|
|
235
|
+
Title of the plot. The default is ``None``.
|
|
236
|
+
style : StyleTemplate, optional
|
|
237
|
+
Style configuration. The default is `BUBBLE_STYLE_TEMPLATE`.
|
|
238
|
+
max_values : int, optional
|
|
239
|
+
Maximum number of rows to display in the chart. The default is 50.
|
|
240
|
+
center_to_mean : bool, optional
|
|
241
|
+
Whether to center the bubbles on the mean. The default is `False`.
|
|
242
|
+
filter_by : str, optional
|
|
243
|
+
Column used to filter the data.
|
|
244
|
+
sort_by : str, optional
|
|
245
|
+
Column used to sort the data.
|
|
246
|
+
ascending : bool, optional
|
|
247
|
+
Sort order for the data. The default is `False`.
|
|
248
|
+
table_rows : int, optional
|
|
249
|
+
Number of rows to display in the tables. The default is 10.
|
|
250
|
+
figsize : tuple[float, float], optional
|
|
251
|
+
Size of the created figure. The default is FIG_SIZE.
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
Figure
|
|
256
|
+
Matplotlib figure containing the composite bubble chart and tables.
|
|
257
|
+
"""
|
|
258
|
+
validate_dataframe(pd_df, cols=[label, x, y, z], sort_by=sort_by)
|
|
259
|
+
if style is None:
|
|
260
|
+
style = WORDCLOUD_STYLE_TEMPLATE
|
|
261
|
+
fig = plt.figure(figsize=figsize)
|
|
262
|
+
gs = fig.add_gridspec(
|
|
263
|
+
2,
|
|
264
|
+
2,
|
|
265
|
+
height_ratios=[2, 1],
|
|
266
|
+
width_ratios=[1, 1],
|
|
267
|
+
)
|
|
268
|
+
ax = fig.add_subplot(gs[0, :])
|
|
269
|
+
ax2 = fig.add_subplot(gs[1, 0])
|
|
270
|
+
ax3 = fig.add_subplot(gs[1, 1])
|
|
271
|
+
|
|
272
|
+
aplot_bubble(
|
|
273
|
+
pd_df=pd_df,
|
|
274
|
+
label=label,
|
|
275
|
+
x=x,
|
|
276
|
+
y=y,
|
|
277
|
+
z=z,
|
|
278
|
+
max_values=max_values,
|
|
279
|
+
center_to_mean=center_to_mean,
|
|
280
|
+
sort_by=sort_by,
|
|
281
|
+
ascending=ascending,
|
|
282
|
+
title=title,
|
|
283
|
+
style=style,
|
|
284
|
+
ax=ax,
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
ax2 = aplot_table(
|
|
288
|
+
pd_df=pd_df,
|
|
289
|
+
cols=[label, z, y, x],
|
|
290
|
+
title=f"Top {table_rows}",
|
|
291
|
+
ax=ax2,
|
|
292
|
+
sort_by=sort_by,
|
|
293
|
+
ascending=False,
|
|
294
|
+
max_values=table_rows,
|
|
295
|
+
style=style,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
ax3 = aplot_table(
|
|
299
|
+
pd_df=pd_df,
|
|
300
|
+
cols=[label, z, y, x],
|
|
301
|
+
title=f"Last {table_rows}",
|
|
302
|
+
ax=ax3,
|
|
303
|
+
sort_by=sort_by,
|
|
304
|
+
ascending=True,
|
|
305
|
+
max_values=table_rows,
|
|
306
|
+
style=style,
|
|
307
|
+
)
|
|
308
|
+
if title:
|
|
309
|
+
fig.tight_layout(rect=(0, 0, 1, 0.95))
|
|
310
|
+
else:
|
|
311
|
+
fig.tight_layout()
|
|
312
|
+
return fig
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def fplot_wordcloud_network2(
|
|
316
|
+
edges_df: pd.DataFrame,
|
|
317
|
+
edge_source_col: str = "source",
|
|
318
|
+
edge_target_col: str = "target",
|
|
319
|
+
edge_weight_col: str = "weight",
|
|
320
|
+
max_words: int = MAX_RESULTS,
|
|
321
|
+
stopwords: Optional[Iterable[str]] = None,
|
|
322
|
+
title: Optional[str] = None,
|
|
323
|
+
style: Optional[StyleTemplate] = None,
|
|
324
|
+
wordcloud_style: Optional[StyleTemplate] = None,
|
|
325
|
+
network_style: Optional[StyleTemplate] = None,
|
|
326
|
+
figsize: Tuple[float, float] = FIG_SIZE,
|
|
327
|
+
) -> Figure:
|
|
328
|
+
"""Plot a word cloud above a network graph.
|
|
329
|
+
|
|
330
|
+
Parameters
|
|
331
|
+
----------
|
|
332
|
+
edges_df : pd.DataFrame
|
|
333
|
+
DataFrame containing edge connections for the network plot.
|
|
334
|
+
edge_source_col : str, optional
|
|
335
|
+
Column in ``edges_df`` containing source nodes. The default is ``"source"``.
|
|
336
|
+
edge_target_col : str, optional
|
|
337
|
+
Column in ``edges_df`` containing target nodes. The default is ``"target"``.
|
|
338
|
+
edge_weight_col : str, optional
|
|
339
|
+
Column in ``edges_df`` containing edge weights. The default is ``"weight"``.
|
|
340
|
+
max_words : int, optional
|
|
341
|
+
Maximum number of words to include in the word cloud. The default is ``50``.
|
|
342
|
+
stopwords : Iterable[str], optional
|
|
343
|
+
Stopwords to exclude from the word cloud. The default is ``None``.
|
|
344
|
+
title : str, optional
|
|
345
|
+
Title for the composite figure. The default is ``None``.
|
|
346
|
+
style : StyleTemplate, optional
|
|
347
|
+
Shared style configuration applied to the composite figure and used for
|
|
348
|
+
subplots when specialized styles are not provided. The default is
|
|
349
|
+
``WORDCLOUD_STYLE_TEMPLATE``.
|
|
350
|
+
wordcloud_style : StyleTemplate, optional
|
|
351
|
+
Optional style configuration for the word cloud subplot. When ``None``
|
|
352
|
+
the shared ``style`` is used. The default is ``None``.
|
|
353
|
+
network_style : StyleTemplate, optional
|
|
354
|
+
Optional style configuration for the network subplot. When ``None`` the
|
|
355
|
+
shared ``style`` is used. The default is ``None``.
|
|
356
|
+
figsize : tuple[float, float], optional
|
|
357
|
+
Size of the composite figure. The default is ``FIG_SIZE``.
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
-------
|
|
361
|
+
Figure
|
|
362
|
+
Matplotlib figure containing the word cloud on top and network below.
|
|
363
|
+
"""
|
|
364
|
+
if not style:
|
|
365
|
+
style = WORDCLOUD_STYLE_TEMPLATE
|
|
366
|
+
fig_raw, axes_raw = plt.subplots(
|
|
367
|
+
2,
|
|
368
|
+
1,
|
|
369
|
+
figsize=figsize,
|
|
370
|
+
gridspec_kw={"height_ratios": [1, 2]},
|
|
371
|
+
)
|
|
372
|
+
fig = cast(Figure, fig_raw)
|
|
373
|
+
wordcloud_ax, network_ax = cast(Tuple[Axes, Axes], axes_raw)
|
|
374
|
+
|
|
375
|
+
wordcloud_style = wordcloud_style or style
|
|
376
|
+
network_style = network_style or style
|
|
377
|
+
|
|
378
|
+
fig.set_facecolor(style.background_color)
|
|
379
|
+
if title:
|
|
380
|
+
fig.suptitle(
|
|
381
|
+
title,
|
|
382
|
+
color=style.font_color,
|
|
383
|
+
fontsize=style.font_size * TITLE_SCALE_FACTOR,
|
|
384
|
+
fontname=style.font_name,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
network = NetworkGraph.from_pandas_edgelist(
|
|
388
|
+
edges_df=edges_df,
|
|
389
|
+
source=edge_source_col,
|
|
390
|
+
target=edge_target_col,
|
|
391
|
+
edge_weight_col=edge_weight_col,
|
|
392
|
+
)
|
|
393
|
+
network.aplot(
|
|
394
|
+
title=None,
|
|
395
|
+
style=network_style,
|
|
396
|
+
ax=network_ax,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
aplot_wordcloud(
|
|
400
|
+
pd_df=network.node_view.to_dataframe(),
|
|
401
|
+
text_column="node",
|
|
402
|
+
weight_column=edge_weight_col,
|
|
403
|
+
title=None,
|
|
404
|
+
style=wordcloud_style,
|
|
405
|
+
max_words=max_words,
|
|
406
|
+
stopwords=stopwords,
|
|
407
|
+
ax=wordcloud_ax,
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
if title:
|
|
411
|
+
fig.tight_layout(rect=(0, 0, 1, 0.95))
|
|
412
|
+
else:
|
|
413
|
+
fig.tight_layout()
|
|
414
|
+
return fig
|
|
415
|
+
|
|
416
|
+
|
|
199
417
|
def fplot_wordcloud_network(
|
|
200
418
|
node_df: pd.DataFrame,
|
|
201
419
|
edges_df: pd.DataFrame,
|
|
@@ -205,7 +423,7 @@ def fplot_wordcloud_network(
|
|
|
205
423
|
max_words: int = MAX_RESULTS,
|
|
206
424
|
stopwords: Optional[Iterable[str]] = None,
|
|
207
425
|
title: Optional[str] = None,
|
|
208
|
-
style: StyleTemplate =
|
|
426
|
+
style: Optional[StyleTemplate] = None,
|
|
209
427
|
wordcloud_style: Optional[StyleTemplate] = None,
|
|
210
428
|
network_style: Optional[StyleTemplate] = None,
|
|
211
429
|
figsize: Tuple[float, float] = FIG_SIZE,
|
|
@@ -246,6 +464,8 @@ def fplot_wordcloud_network(
|
|
|
246
464
|
Figure
|
|
247
465
|
Matplotlib figure containing the word cloud on top and network below.
|
|
248
466
|
"""
|
|
467
|
+
if not style:
|
|
468
|
+
style = WORDCLOUD_STYLE_TEMPLATE
|
|
249
469
|
fig_raw, axes_raw = plt.subplots(
|
|
250
470
|
2,
|
|
251
471
|
1,
|
MatplotLibAPI/heatmap.py
CHANGED
|
@@ -6,17 +6,15 @@ import pandas as pd
|
|
|
6
6
|
import seaborn as sns
|
|
7
7
|
from matplotlib.axes import Axes
|
|
8
8
|
from matplotlib.figure import Figure
|
|
9
|
-
from pandas.api.extensions import register_dataframe_accessor
|
|
10
9
|
|
|
11
10
|
from .base_plot import BasePlot
|
|
11
|
+
from .types import CorrelationMethod
|
|
12
12
|
from .style_template import (
|
|
13
13
|
HEATMAP_STYLE_TEMPLATE,
|
|
14
14
|
StyleTemplate,
|
|
15
15
|
string_formatter,
|
|
16
16
|
validate_dataframe,
|
|
17
17
|
)
|
|
18
|
-
from .typing import CorrelationMethod
|
|
19
|
-
from .utils import _get_axis, _merge_kwargs
|
|
20
18
|
|
|
21
19
|
__all__ = [
|
|
22
20
|
"HEATMAP_STYLE_TEMPLATE",
|
|
@@ -27,7 +25,6 @@ __all__ = [
|
|
|
27
25
|
]
|
|
28
26
|
|
|
29
27
|
|
|
30
|
-
@register_dataframe_accessor("heatmap")
|
|
31
28
|
class Heatmap(BasePlot):
|
|
32
29
|
"""Class for plotting heatmaps and correlation matrices."""
|
|
33
30
|
|
|
@@ -43,26 +40,30 @@ class Heatmap(BasePlot):
|
|
|
43
40
|
self.y = y
|
|
44
41
|
self.value = value
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
def correlation_matrix(
|
|
44
|
+
self,
|
|
45
|
+
correlation_method: CorrelationMethod = "pearson",
|
|
46
|
+
) -> pd.DataFrame:
|
|
48
47
|
"""Compute the correlation matrix for the underlying DataFrame."""
|
|
49
|
-
return self._obj.corr()
|
|
48
|
+
return self._obj.corr(method=correlation_method)
|
|
50
49
|
|
|
51
50
|
def aplot(
|
|
52
51
|
self,
|
|
53
52
|
title: Optional[str] = None,
|
|
54
|
-
style: StyleTemplate =
|
|
53
|
+
style: Optional[StyleTemplate] = None,
|
|
55
54
|
ax: Optional[Axes] = None,
|
|
56
55
|
**kwargs: Any,
|
|
57
56
|
) -> Axes:
|
|
58
57
|
"""Plot a heatmap on an existing Matplotlib axes."""
|
|
59
|
-
|
|
58
|
+
if not style:
|
|
59
|
+
style = HEATMAP_STYLE_TEMPLATE
|
|
60
|
+
plot_ax = BasePlot.get_axis(ax)
|
|
60
61
|
heatmap_kwargs: dict[str, Any] = {
|
|
61
62
|
"data": self._obj,
|
|
62
63
|
"cmap": style.palette,
|
|
63
64
|
"ax": plot_ax,
|
|
64
65
|
}
|
|
65
|
-
sns.heatmap(**
|
|
66
|
+
sns.heatmap(**BasePlot.merge_kwargs(heatmap_kwargs, kwargs))
|
|
66
67
|
|
|
67
68
|
plot_ax.set_xlabel(string_formatter(self.x))
|
|
68
69
|
plot_ax.set_ylabel(string_formatter(self.y))
|
|
@@ -70,40 +71,26 @@ class Heatmap(BasePlot):
|
|
|
70
71
|
plot_ax.set_title(title)
|
|
71
72
|
return plot_ax
|
|
72
73
|
|
|
73
|
-
def fplot(
|
|
74
|
-
self,
|
|
75
|
-
title: Optional[str] = None,
|
|
76
|
-
style: StyleTemplate = HEATMAP_STYLE_TEMPLATE,
|
|
77
|
-
figsize: Tuple[float, float] = (10, 6),
|
|
78
|
-
) -> Figure:
|
|
79
|
-
"""Plot a heatmap on a new Matplotlib figure."""
|
|
80
|
-
fig = Figure(
|
|
81
|
-
figsize=figsize,
|
|
82
|
-
facecolor=style.background_color,
|
|
83
|
-
edgecolor=style.background_color,
|
|
84
|
-
)
|
|
85
|
-
ax = fig.add_subplot(111)
|
|
86
|
-
ax.set_facecolor(style.background_color)
|
|
87
|
-
self.aplot(title=title, style=style, ax=ax)
|
|
88
|
-
return fig
|
|
89
|
-
|
|
90
74
|
def aplot_correlation_matrix(
|
|
91
75
|
self,
|
|
92
76
|
title: Optional[str] = None,
|
|
93
|
-
style: StyleTemplate =
|
|
77
|
+
style: Optional[StyleTemplate] = None,
|
|
78
|
+
correlation_method: CorrelationMethod = "pearson",
|
|
94
79
|
ax: Optional[Axes] = None,
|
|
95
80
|
**kwargs: Any,
|
|
96
81
|
) -> Axes:
|
|
97
82
|
"""Plot a correlation matrix heatmap on existing axes."""
|
|
98
|
-
|
|
83
|
+
if not style:
|
|
84
|
+
style = HEATMAP_STYLE_TEMPLATE
|
|
85
|
+
plot_ax = BasePlot.get_axis(ax)
|
|
99
86
|
heatmap_kwargs: dict[str, Any] = {
|
|
100
|
-
"data": self.correlation_matrix,
|
|
87
|
+
"data": self.correlation_matrix(correlation_method),
|
|
101
88
|
"cmap": style.palette,
|
|
102
89
|
"annot": True,
|
|
103
90
|
"fmt": ".2f",
|
|
104
91
|
"ax": plot_ax,
|
|
105
92
|
}
|
|
106
|
-
sns.heatmap(**
|
|
93
|
+
sns.heatmap(**BasePlot.merge_kwargs(heatmap_kwargs, kwargs))
|
|
107
94
|
if title:
|
|
108
95
|
plot_ax.set_title(title)
|
|
109
96
|
return plot_ax
|
|
@@ -111,20 +98,18 @@ class Heatmap(BasePlot):
|
|
|
111
98
|
def fplot_correlation_matrix(
|
|
112
99
|
self,
|
|
113
100
|
title: Optional[str] = None,
|
|
114
|
-
style: StyleTemplate =
|
|
101
|
+
style: Optional[StyleTemplate] = None,
|
|
115
102
|
figsize: Tuple[float, float] = (10, 6),
|
|
103
|
+
correlation_method: CorrelationMethod = "pearson",
|
|
116
104
|
) -> Figure:
|
|
117
105
|
"""Plot a correlation matrix heatmap on a new figure."""
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
edgecolor=style.background_color,
|
|
122
|
-
)
|
|
123
|
-
ax = fig.add_subplot(111)
|
|
124
|
-
ax.set_facecolor(style.background_color)
|
|
106
|
+
if not style:
|
|
107
|
+
style = HEATMAP_STYLE_TEMPLATE
|
|
108
|
+
fig, ax = BasePlot.create_fig(figsize=figsize, style=style)
|
|
125
109
|
self.aplot_correlation_matrix(
|
|
126
110
|
title=title,
|
|
127
111
|
style=style,
|
|
112
|
+
correlation_method=correlation_method,
|
|
128
113
|
ax=ax,
|
|
129
114
|
)
|
|
130
115
|
return fig
|
|
@@ -163,7 +148,7 @@ def aplot_heatmap(
|
|
|
163
148
|
y: str,
|
|
164
149
|
value: str,
|
|
165
150
|
title: Optional[str] = None,
|
|
166
|
-
style: StyleTemplate =
|
|
151
|
+
style: Optional[StyleTemplate] = None,
|
|
167
152
|
ax: Optional[Axes] = None,
|
|
168
153
|
**kwargs: Any,
|
|
169
154
|
) -> Axes:
|
|
@@ -183,27 +168,51 @@ def aplot_heatmap(
|
|
|
183
168
|
|
|
184
169
|
def aplot_correlation_matrix(
|
|
185
170
|
pd_df: pd.DataFrame,
|
|
186
|
-
|
|
187
|
-
|
|
171
|
+
x: str,
|
|
172
|
+
y: str,
|
|
173
|
+
value: str,
|
|
174
|
+
correlation_method: CorrelationMethod = "pearson",
|
|
188
175
|
title: Optional[str] = None,
|
|
189
|
-
style: StyleTemplate =
|
|
176
|
+
style: Optional[StyleTemplate] = None,
|
|
190
177
|
ax: Optional[Axes] = None,
|
|
191
178
|
**kwargs: Any,
|
|
192
179
|
) -> Axes:
|
|
193
|
-
"""Plot a correlation matrix heatmap
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
180
|
+
"""Plot a correlation matrix heatmap on existing Matplotlib axes.
|
|
181
|
+
|
|
182
|
+
Parameters
|
|
183
|
+
----------
|
|
184
|
+
pd_df : pd.DataFrame
|
|
185
|
+
Source dataframe containing correlation inputs.
|
|
186
|
+
x : str
|
|
187
|
+
Column used for heatmap x-axis labels.
|
|
188
|
+
y : str
|
|
189
|
+
Column used for heatmap y-axis labels.
|
|
190
|
+
value : str
|
|
191
|
+
Column providing values before correlation aggregation.
|
|
192
|
+
correlation_method : CorrelationMethod, optional
|
|
193
|
+
Correlation method. The default is ``"pearson"``.
|
|
194
|
+
title : str, optional
|
|
195
|
+
Plot title. The default is ``None``.
|
|
196
|
+
style : StyleTemplate, optional
|
|
197
|
+
Style template for rendering. The default is ``None``.
|
|
198
|
+
ax : Axes, optional
|
|
199
|
+
Matplotlib axes to draw on. If ``None``, use current axes.
|
|
200
|
+
**kwargs : Any
|
|
201
|
+
Additional keyword arguments forwarded to seaborn.
|
|
202
|
+
|
|
203
|
+
Returns
|
|
204
|
+
-------
|
|
205
|
+
Axes
|
|
206
|
+
The Matplotlib axes containing the correlation heatmap.
|
|
207
|
+
"""
|
|
208
|
+
return Heatmap(
|
|
209
|
+
pd_df=pd_df,
|
|
210
|
+
x=x,
|
|
211
|
+
y=y,
|
|
212
|
+
value=value,
|
|
213
|
+
).aplot_correlation_matrix(
|
|
214
|
+
title=title, style=style, correlation_method=correlation_method, ax=ax
|
|
215
|
+
)
|
|
207
216
|
|
|
208
217
|
|
|
209
218
|
def fplot_heatmap(
|
|
@@ -212,7 +221,7 @@ def fplot_heatmap(
|
|
|
212
221
|
y: str,
|
|
213
222
|
value: str,
|
|
214
223
|
title: Optional[str] = None,
|
|
215
|
-
style: StyleTemplate =
|
|
224
|
+
style: Optional[StyleTemplate] = None,
|
|
216
225
|
figsize: Tuple[float, float] = (10, 6),
|
|
217
226
|
) -> Figure:
|
|
218
227
|
"""Plot a matrix heatmap on a new figure."""
|
|
@@ -234,8 +243,9 @@ def fplot_correlation_matrix(
|
|
|
234
243
|
y: str,
|
|
235
244
|
value: str,
|
|
236
245
|
title: Optional[str] = None,
|
|
237
|
-
style: StyleTemplate =
|
|
246
|
+
style: Optional[StyleTemplate] = None,
|
|
238
247
|
figsize: Tuple[float, float] = (10, 6),
|
|
248
|
+
correlation_method: CorrelationMethod = "pearson",
|
|
239
249
|
) -> Figure:
|
|
240
250
|
"""Plot a correlation matrix heatmap on a new figure."""
|
|
241
251
|
return Heatmap(
|
|
@@ -243,4 +253,6 @@ def fplot_correlation_matrix(
|
|
|
243
253
|
x=x,
|
|
244
254
|
y=y,
|
|
245
255
|
value=value,
|
|
246
|
-
).fplot_correlation_matrix(
|
|
256
|
+
).fplot_correlation_matrix(
|
|
257
|
+
title=title, style=style, figsize=figsize, correlation_method=correlation_method
|
|
258
|
+
)
|
MatplotLibAPI/histogram.py
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
from typing import Any, Optional, Tuple
|
|
4
4
|
|
|
5
5
|
import pandas as pd
|
|
6
|
-
from pandas.api.extensions import register_dataframe_accessor
|
|
7
6
|
import seaborn as sns
|
|
8
|
-
import matplotlib.pyplot as plt
|
|
9
7
|
from matplotlib.axes import Axes
|
|
10
8
|
from matplotlib.figure import Figure
|
|
11
9
|
|
|
@@ -19,12 +17,10 @@ from .style_template import (
|
|
|
19
17
|
string_formatter,
|
|
20
18
|
validate_dataframe,
|
|
21
19
|
)
|
|
22
|
-
from .utils import _get_axis, _merge_kwargs
|
|
23
20
|
|
|
24
21
|
__all__ = ["DISTRIBUTION_STYLE_TEMPLATE", "aplot_histogram", "fplot_histogram"]
|
|
25
22
|
|
|
26
23
|
|
|
27
|
-
@register_dataframe_accessor("histogram")
|
|
28
24
|
class Histogram(BasePlot):
|
|
29
25
|
"""Class for plotting histograms with optional KDE."""
|
|
30
26
|
|
|
@@ -49,7 +45,7 @@ class Histogram(BasePlot):
|
|
|
49
45
|
) -> Axes:
|
|
50
46
|
|
|
51
47
|
validate_dataframe(self._obj, cols=[self.column])
|
|
52
|
-
plot_ax =
|
|
48
|
+
plot_ax = BasePlot.get_axis(ax)
|
|
53
49
|
histplot_kwargs: dict[str, Any] = {
|
|
54
50
|
"data": self._obj,
|
|
55
51
|
"x": self.column,
|
|
@@ -59,7 +55,7 @@ class Histogram(BasePlot):
|
|
|
59
55
|
"edgecolor": style.background_color,
|
|
60
56
|
"ax": plot_ax,
|
|
61
57
|
}
|
|
62
|
-
sns.histplot(**
|
|
58
|
+
sns.histplot(**BasePlot.merge_kwargs(histplot_kwargs, kwargs))
|
|
63
59
|
plot_ax.set_facecolor(style.background_color)
|
|
64
60
|
plot_ax.set_xlabel(string_formatter(self.column))
|
|
65
61
|
plot_ax.set_ylabel("Frequency")
|
|
@@ -67,26 +63,6 @@ class Histogram(BasePlot):
|
|
|
67
63
|
plot_ax.set_title(title)
|
|
68
64
|
return plot_ax
|
|
69
65
|
|
|
70
|
-
def fplot(
|
|
71
|
-
self,
|
|
72
|
-
title: Optional[str] = None,
|
|
73
|
-
style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
|
|
74
|
-
figsize: Tuple[float, float] = (10, 6),
|
|
75
|
-
) -> Figure:
|
|
76
|
-
fig = Figure(
|
|
77
|
-
figsize=figsize,
|
|
78
|
-
facecolor=style.background_color,
|
|
79
|
-
edgecolor=style.background_color,
|
|
80
|
-
)
|
|
81
|
-
ax = fig.add_subplot(111)
|
|
82
|
-
ax.set_facecolor(style.background_color)
|
|
83
|
-
self.aplot(
|
|
84
|
-
title=title,
|
|
85
|
-
style=style,
|
|
86
|
-
ax=ax,
|
|
87
|
-
)
|
|
88
|
-
return fig
|
|
89
|
-
|
|
90
66
|
|
|
91
67
|
def aplot_histogram(
|
|
92
68
|
pd_df: pd.DataFrame,
|
|
@@ -7,6 +7,7 @@ organizing implementation details in submodules.
|
|
|
7
7
|
from .constants import _DEFAULT, _WEIGHT_PERCENTILES
|
|
8
8
|
from .core import NETWORK_STYLE_TEMPLATE, NetworkGraph
|
|
9
9
|
from .plot import (
|
|
10
|
+
trim_low_degree_nodes,
|
|
10
11
|
aplot_network,
|
|
11
12
|
aplot_network_node,
|
|
12
13
|
aplot_network_components,
|
|
@@ -17,6 +18,7 @@ from .plot import (
|
|
|
17
18
|
from .scaling import _scale_weights, _softmax
|
|
18
19
|
|
|
19
20
|
__all__ = [
|
|
21
|
+
"trim_low_degree_nodes",
|
|
20
22
|
"aplot_network",
|
|
21
23
|
"aplot_network_node",
|
|
22
24
|
"aplot_network_components",
|