MatplotLibAPI 3.2.15__py3-none-any.whl → 3.2.17__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/Heatmap.py CHANGED
@@ -7,7 +7,6 @@ import pandas as pd
7
7
  import seaborn as sns
8
8
  from matplotlib.axes import Axes
9
9
  from matplotlib.figure import Figure
10
- from pandas._typing import CorrelationMethod
11
10
 
12
11
  from .StyleTemplate import (
13
12
  HEATMAP_STYLE_TEMPLATE,
@@ -16,6 +15,7 @@ from .StyleTemplate import (
16
15
  validate_dataframe,
17
16
  )
18
17
  from ._visualization_utils import _get_axis, _wrap_aplot
18
+ from ._typing import CorrelationMethod
19
19
 
20
20
 
21
21
  def aplot_heatmap(
@@ -10,6 +10,7 @@ import matplotlib.pyplot as plt
10
10
  from matplotlib import colormaps
11
11
  from matplotlib.axes import Axes
12
12
  from matplotlib.figure import Figure
13
+ from wordcloud import WordCloud
13
14
 
14
15
  from .StyleTemplate import (
15
16
  FIG_SIZE,
@@ -160,29 +161,43 @@ def _plot_words(
160
161
  matplotlib.axes.Axes
161
162
  Axes containing the rendered word cloud.
162
163
  """
163
- rng = np.random.default_rng(seed=random_state)
164
- font_sizes = _normalize_weights(weights, base_size=style.font_size)
165
- cmap = colormaps.get_cmap(style.palette)
166
-
167
164
  ax.set_facecolor(style.background_color)
168
165
  ax.axis("off")
169
166
 
170
- x_positions = rng.uniform(0.05, 0.95, size=len(words))
171
- y_positions = rng.uniform(0.05, 0.95, size=len(words))
172
-
173
- for idx, (word, weight) in enumerate(zip(words, weights)):
174
- size = font_sizes[idx]
175
- color = cmap(rng.random())
176
- ax.text(
177
- x_positions[idx],
178
- y_positions[idx],
179
- string_formatter(word),
180
- ha="center",
181
- va="center",
182
- fontsize=size,
183
- color=color,
184
- transform=ax.transAxes,
185
- )
167
+ if not words:
168
+ if title:
169
+ ax.set_title(title, color=style.font_color, fontsize=style.font_size * 1.5)
170
+ return ax
171
+
172
+ fig_obj = ax.get_figure()
173
+ if not isinstance(fig_obj, Figure):
174
+ raise RuntimeError("Axes is not associated with a Figure.")
175
+
176
+ canvas = fig_obj.canvas
177
+ if canvas is None:
178
+ raise RuntimeError("Figure does not have an attached canvas.")
179
+
180
+ canvas.draw()
181
+ ax_bbox = ax.get_window_extent()
182
+ width = max(int(ax_bbox.width), 1)
183
+ height = max(int(ax_bbox.height), 1)
184
+
185
+ frequency_map = {
186
+ string_formatter(word): weight for word, weight in zip(words, weights)
187
+ }
188
+
189
+ font_sizes = _normalize_weights(weights, base_size=style.font_size)
190
+ wc = WordCloud(
191
+ width=width,
192
+ height=height,
193
+ background_color=style.background_color,
194
+ colormap=colormaps.get_cmap(style.palette),
195
+ min_font_size=int(font_sizes.min(initial=style.font_size)),
196
+ max_font_size=int(font_sizes.max(initial=style.font_size * 4)),
197
+ random_state=random_state,
198
+ ).generate_from_frequencies(frequency_map)
199
+
200
+ ax.imshow(wc, interpolation="bilinear")
186
201
 
187
202
  if title:
188
203
  ax.set_title(title, color=style.font_color, fontsize=style.font_size * 1.5)
MatplotLibAPI/__init__.py CHANGED
@@ -17,6 +17,7 @@ from .Network import (
17
17
  NETWORK_STYLE_TEMPLATE,
18
18
  aplot_network,
19
19
  aplot_network_components,
20
+ fplot_network_components,
20
21
  fplot_network,
21
22
  prepare_network_graph,
22
23
  )
@@ -56,6 +57,7 @@ __all__ = [
56
57
  "aplot_waffle",
57
58
  "fplot_bubble",
58
59
  "fplot_network",
60
+ "fplot_network_components",
59
61
  "fplot_table",
60
62
  "fplot_timeserie",
61
63
  "fplot_wordcloud",
@@ -0,0 +1,17 @@
1
+ """Internal type aliases used across MatplotLibAPI."""
2
+
3
+ from typing import Any, Callable, Literal, Union
4
+
5
+ from typing_extensions import TypeAlias
6
+
7
+ import numpy.typing as npt
8
+
9
+
10
+ # ``DataFrame.corr`` supports the three built-in correlation methods or a callable
11
+ # that operates on two array-like inputs and returns a float. Using a local alias
12
+ # avoids depending on the private ``pandas._typing`` module, which is not
13
+ # considered stable across releases.
14
+ CorrelationMethod: TypeAlias = Union[
15
+ Literal["pearson", "kendall", "spearman"],
16
+ Callable[[npt.NDArray[Any], npt.NDArray[Any]], float],
17
+ ]
MatplotLibAPI/accessor.py CHANGED
@@ -7,7 +7,6 @@ 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 pandas._typing import CorrelationMethod
11
10
  from pandas.api.extensions import register_dataframe_accessor
12
11
 
13
12
  from .Area import aplot_area, fplot_area
@@ -27,6 +26,7 @@ from .Network import (
27
26
  NETWORK_STYLE_TEMPLATE,
28
27
  aplot_network,
29
28
  aplot_network_components,
29
+ fplot_network_components,
30
30
  fplot_network,
31
31
  )
32
32
  from .Pie import aplot_pie_donut, fplot_pie_donut
@@ -40,6 +40,7 @@ from .StyleTemplate import (
40
40
  TREEMAP_STYLE_TEMPLATE,
41
41
  StyleTemplate,
42
42
  )
43
+ from ._typing import CorrelationMethod
43
44
  from .Table import aplot_table, fplot_table
44
45
  from .Timeserie import aplot_timeserie, fplot_timeserie
45
46
  from .Sunburst import fplot_sunburst
@@ -112,6 +113,8 @@ class DataFrameAccessor:
112
113
  Plot connected components of a network graph on multiple axes.
113
114
  fplot_network
114
115
  Plot a network graph on a new figure.
116
+ fplot_network_components
117
+ Plot connected components of a network graph on a new figure.
115
118
  fplot_treemap
116
119
  Plot a treemap on a new Plotly figure.
117
120
  fplot_sunburst
@@ -1483,6 +1486,63 @@ class DataFrameAccessor:
1483
1486
  figsize=figsize,
1484
1487
  )
1485
1488
 
1489
+ def fplot_network_components(
1490
+ self,
1491
+ source: str = "source",
1492
+ target: str = "target",
1493
+ weight: str = "weight",
1494
+ title: Optional[str] = None,
1495
+ style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
1496
+ sort_by: Optional[str] = None,
1497
+ ascending: bool = False,
1498
+ node_list: Optional[List] = None,
1499
+ figsize: Tuple[float, float] = (19.2, 10.8),
1500
+ n_cols: Optional[int] = None,
1501
+ ) -> Figure:
1502
+ """Plot network components on a new figure.
1503
+
1504
+ Parameters
1505
+ ----------
1506
+ source : str, optional
1507
+ Column for source nodes. The default is "source".
1508
+ target : str, optional
1509
+ Column for target nodes. The default is "target".
1510
+ weight : str, optional
1511
+ Column for edge weights. The default is "weight".
1512
+ title : str, optional
1513
+ Chart title.
1514
+ style : StyleTemplate, optional
1515
+ Styling template. The default is `NETWORK_STYLE_TEMPLATE`.
1516
+ sort_by : str, optional
1517
+ Column to sort by.
1518
+ ascending : bool, optional
1519
+ Sort order. The default is `False`.
1520
+ node_list : list, optional
1521
+ List of nodes to include. If None, all nodes are used.
1522
+ figsize : tuple[float, float], optional
1523
+ Figure size. The default is (19.2, 10.8).
1524
+ n_cols : int, optional
1525
+ Number of columns for arranging component subplots.
1526
+
1527
+ Returns
1528
+ -------
1529
+ Figure
1530
+ The new Matplotlib figure with component plots.
1531
+ """
1532
+ return fplot_network_components(
1533
+ pd_df=self._obj,
1534
+ source=source,
1535
+ target=target,
1536
+ weight=weight,
1537
+ title=title,
1538
+ style=style,
1539
+ sort_by=sort_by,
1540
+ ascending=ascending,
1541
+ node_list=node_list,
1542
+ figsize=figsize,
1543
+ n_cols=n_cols,
1544
+ )
1545
+
1486
1546
  def fplot_treemap(
1487
1547
  self,
1488
1548
  path: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MatplotLibAPI
3
- Version: 3.2.15
3
+ Version: 3.2.17
4
4
  License-File: LICENSE
5
5
  Requires-Python: >=3.8
6
6
  Requires-Dist: kaleido
@@ -12,6 +12,7 @@ Requires-Dist: pandas
12
12
  Requires-Dist: plotly
13
13
  Requires-Dist: scikit-learn
14
14
  Requires-Dist: seaborn
15
+ Requires-Dist: wordcloud
15
16
  Provides-Extra: dev
16
17
  Requires-Dist: black; extra == 'dev'
17
18
  Requires-Dist: pydocstyle; extra == 'dev'
@@ -3,7 +3,7 @@ MatplotLibAPI/Bar.py,sha256=WY74gXJA3ZIpJD0WaidMo0lrT1lVEbeA0UMGFBY5yiE,2079
3
3
  MatplotLibAPI/BoxViolin.py,sha256=XB4cUxUvf8LzwE2twu0gd7vn2NJYjz_mQwVqtyE7dYU,1783
4
4
  MatplotLibAPI/Bubble.py,sha256=PiK6Fe77mXRTSSewXkimrNFsMa32pGRXr9jlgZJndXA,12644
5
5
  MatplotLibAPI/Composite.py,sha256=k4elPk2mucw5oOH2S2GZV6mbHI9N4Nhpnte4mWLHObg,5902
6
- MatplotLibAPI/Heatmap.py,sha256=OAF6oBXUksRKGgbN5Mn3EkZxOOZmD4LaJmk4mC01jN8,3053
6
+ MatplotLibAPI/Heatmap.py,sha256=Qs17CHGhBDXUVDxW0dofzjO5xxlQw5XIwANtUKHgg_Y,3047
7
7
  MatplotLibAPI/Histogram.py,sha256=0J4uC7xy53TZKjTDWCeEjaELL7E5lQDG0MpeGfaaO6Y,1705
8
8
  MatplotLibAPI/Network.py,sha256=erjKzl1Jb6j6Fiy3170xKSeF1LEBe7jPdLB6q8VZclw,30142
9
9
  MatplotLibAPI/Pie.py,sha256=TBAnj4mVYy6dKPMwXPjGanTDrLrjHmA5pFvrdXbNw9A,1724
@@ -15,11 +15,12 @@ MatplotLibAPI/Table.py,sha256=EBxXJA6GKjFhWcOMwJ6Wfm-UNw3Ha5KBZ2004TYdkKY,6272
15
15
  MatplotLibAPI/Timeserie.py,sha256=s6u68IlugqPMpJk-X5hr-k1WDZyx97Ov7VKQOztXo_U,10028
16
16
  MatplotLibAPI/Treemap.py,sha256=a-9Z-ZzXzIV5SDgdJaW7slGELFBBks1pXZnIjcYmarw,4528
17
17
  MatplotLibAPI/Waffle.py,sha256=gPREV5v92DQcvjNGuwdKDbAaRSzLBbGF8sWPGUwFyJM,2353
18
- MatplotLibAPI/Wordcloud.py,sha256=b0vXLRjclSDr28o6LSXqnQenT7duZMmldmfyLrNOVro,9333
19
- MatplotLibAPI/__init__.py,sha256=StUMlDJehHrO_LMCxmmMX3NpT0Ua_POCZ8GcHHpsQ5Y,2171
18
+ MatplotLibAPI/Wordcloud.py,sha256=aQnLQ4AxHaa2-6PE3ThbmjoQF4DN4oYTaRgRur_evRc,9840
19
+ MatplotLibAPI/__init__.py,sha256=6Z51NTmLCoM7P-XPDGVQdtcXtz8S1zZzoByuX_nCpyw,2233
20
+ MatplotLibAPI/_typing.py,sha256=Or3IPNceWKdyEk3CGXJb09FZR_fvT732oF0iWrx1ex8,598
20
21
  MatplotLibAPI/_visualization_utils.py,sha256=RQBgS-ytPorEOuWqQMHJRwaKOgmZoMW22-sjzxkui2I,1179
21
- MatplotLibAPI/accessor.py,sha256=I497w2I9vIA9Imc3f00KiW0_a2-VABl_vHgLwRYejPE,50814
22
- matplotlibapi-3.2.15.dist-info/METADATA,sha256=xkpRcdXfSkx0jwSCVAn-NXu4sYxuu0EXNWyiS5mSf6g,5863
23
- matplotlibapi-3.2.15.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
24
- matplotlibapi-3.2.15.dist-info/licenses/LICENSE,sha256=hMErKLb6YZR3lRR5zr-vxeFkvY69QAaafgSpZ5-P1dQ,1067
25
- matplotlibapi-3.2.15.dist-info/RECORD,,
22
+ MatplotLibAPI/accessor.py,sha256=jcLrMP30v_G4rMNV1_peM-_cpxk6bIh11snvHGAUUpE,52859
23
+ matplotlibapi-3.2.17.dist-info/METADATA,sha256=g6-L4pc_nY0GtaopfPavA5ANDLVyhd7fTJ-McH6VNYo,5888
24
+ matplotlibapi-3.2.17.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
25
+ matplotlibapi-3.2.17.dist-info/licenses/LICENSE,sha256=hMErKLb6YZR3lRR5zr-vxeFkvY69QAaafgSpZ5-P1dQ,1067
26
+ matplotlibapi-3.2.17.dist-info/RECORD,,