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.
Files changed (51) hide show
  1. MatplotLibAPI/__init__.py +4 -86
  2. MatplotLibAPI/accessor.py +519 -196
  3. MatplotLibAPI/area.py +177 -0
  4. MatplotLibAPI/bar.py +185 -0
  5. MatplotLibAPI/base_plot.py +88 -0
  6. MatplotLibAPI/box_violin.py +180 -0
  7. MatplotLibAPI/bubble.py +568 -0
  8. MatplotLibAPI/{Composite.py → composite.py} +127 -106
  9. MatplotLibAPI/heatmap.py +223 -0
  10. MatplotLibAPI/histogram.py +170 -0
  11. MatplotLibAPI/mcp/__init__.py +17 -0
  12. MatplotLibAPI/mcp/metadata.py +90 -0
  13. MatplotLibAPI/mcp/renderers.py +45 -0
  14. MatplotLibAPI/mcp_server.py +626 -0
  15. MatplotLibAPI/network/__init__.py +28 -0
  16. MatplotLibAPI/network/constants.py +22 -0
  17. MatplotLibAPI/network/core.py +1360 -0
  18. MatplotLibAPI/network/plot.py +597 -0
  19. MatplotLibAPI/network/scaling.py +56 -0
  20. MatplotLibAPI/pie.py +154 -0
  21. MatplotLibAPI/pivot.py +274 -0
  22. MatplotLibAPI/sankey.py +99 -0
  23. MatplotLibAPI/{StyleTemplate.py → style_template.py} +27 -22
  24. MatplotLibAPI/sunburst.py +139 -0
  25. MatplotLibAPI/{Table.py → table.py} +112 -87
  26. MatplotLibAPI/{Timeserie.py → timeserie.py} +98 -42
  27. MatplotLibAPI/{Treemap.py → treemap.py} +43 -55
  28. MatplotLibAPI/typing.py +12 -0
  29. MatplotLibAPI/{_visualization_utils.py → utils.py} +7 -13
  30. MatplotLibAPI/waffle.py +173 -0
  31. MatplotLibAPI/word_cloud.py +489 -0
  32. {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/METADATA +98 -9
  33. matplotlibapi-4.0.0.dist-info/RECORD +36 -0
  34. {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/WHEEL +1 -1
  35. matplotlibapi-4.0.0.dist-info/entry_points.txt +2 -0
  36. MatplotLibAPI/Area.py +0 -80
  37. MatplotLibAPI/Bar.py +0 -83
  38. MatplotLibAPI/BoxViolin.py +0 -75
  39. MatplotLibAPI/Bubble.py +0 -458
  40. MatplotLibAPI/Heatmap.py +0 -121
  41. MatplotLibAPI/Histogram.py +0 -73
  42. MatplotLibAPI/Network.py +0 -989
  43. MatplotLibAPI/Pie.py +0 -70
  44. MatplotLibAPI/Pivot.py +0 -134
  45. MatplotLibAPI/Sankey.py +0 -46
  46. MatplotLibAPI/Sunburst.py +0 -89
  47. MatplotLibAPI/Waffle.py +0 -86
  48. MatplotLibAPI/Wordcloud.py +0 -373
  49. MatplotLibAPI/_typing.py +0 -17
  50. matplotlibapi-3.2.21.dist-info/RECORD +0 -26
  51. {matplotlibapi-3.2.21.dist-info → matplotlibapi-4.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,373 +0,0 @@
1
- """Word cloud plotting utilities."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Any, Dict, Iterable, Optional, Sequence, Tuple, cast
6
-
7
- import numpy as np
8
- import pandas as pd
9
- import matplotlib.pyplot as plt
10
- from matplotlib import colormaps
11
- from matplotlib.axes import Axes
12
- from matplotlib.figure import Figure
13
- from wordcloud import WordCloud
14
-
15
- from .StyleTemplate import (
16
- FIG_SIZE,
17
- MAX_RESULTS,
18
- StyleTemplate,
19
- string_formatter,
20
- validate_dataframe,
21
- )
22
-
23
- WORDCLOUD_STYLE_TEMPLATE = StyleTemplate(
24
- background_color="black", font_color="white", palette="plasma"
25
- )
26
-
27
-
28
- def _filter_stopwords(
29
- words: Iterable[str], stopwords: Optional[Iterable[str]]
30
- ) -> np.ndarray:
31
- """Remove stopwords from a sequence of words.
32
-
33
- Parameters
34
- ----------
35
- words : Iterable[str]
36
- Words to filter.
37
- stopwords : Iterable[str], optional
38
- Collection of stopwords to exclude. Defaults to ``None``.
39
-
40
- Returns
41
- -------
42
- numpy.ndarray
43
- Filtered words.
44
- """
45
- if stopwords is None:
46
- return np.array(list(words))
47
-
48
- stop_set = {word.lower() for word in stopwords}
49
- return np.array([word for word in words if word.lower() not in stop_set])
50
-
51
-
52
- def _prepare_word_frequencies(
53
- pd_df: pd.DataFrame,
54
- text_column: str,
55
- weight_column: Optional[str],
56
- max_words: int,
57
- stopwords: Optional[Iterable[str]],
58
- ) -> Tuple[list[str], list[float]]:
59
- """Aggregate and filter word frequencies.
60
-
61
- Parameters
62
- ----------
63
- pd_df : pandas.DataFrame
64
- Input DataFrame containing word data.
65
- text_column : str
66
- Column containing words or phrases.
67
- weight_column : str, optional
68
- Column containing numeric weights. Defaults to ``None``.
69
- max_words : int
70
- Maximum number of words to include.
71
- stopwords : Iterable[str], optional
72
- Words to exclude from the visualization. Defaults to ``None``.
73
-
74
- Returns
75
- -------
76
- tuple of list
77
- Lists of filtered words and their corresponding weights.
78
-
79
- Raises
80
- ------
81
- AttributeError
82
- If required columns are missing from the DataFrame.
83
- """
84
- validate_dataframe(pd_df, cols=[text_column], sort_by=weight_column)
85
-
86
- if weight_column is None:
87
- freq_series: pd.Series = pd_df[text_column].value_counts()
88
- else:
89
- weight_col = cast(str, weight_column)
90
- freq_series = cast(pd.Series, pd_df.groupby(text_column)[weight_col].sum())
91
- freq_series = freq_series.sort_values(ascending=False)
92
-
93
- words = freq_series.index.to_numpy()
94
- weights = freq_series.to_numpy(dtype=float)
95
-
96
- words = _filter_stopwords(words, stopwords)
97
- mask = np.isin(freq_series.index, words)
98
- weights = weights[mask]
99
-
100
- sorted_indices = np.argsort(weights)[::-1]
101
- words = words[sorted_indices][:max_words].tolist()
102
- weights = weights[sorted_indices][:max_words].tolist()
103
-
104
- return words, weights
105
-
106
-
107
- def create_circular_mask(size: int = 300, radius: Optional[int] = None) -> np.ndarray:
108
- """Construct a binary mask with a circular opening for a word cloud.
109
-
110
- Parameters
111
- ----------
112
- size : int, optional
113
- Width and height of the mask in pixels. Defaults to ``300``.
114
- radius : int, optional
115
- Radius of the circular opening in pixels. Defaults to ``size // 2``.
116
-
117
- Returns
118
- -------
119
- numpy.ndarray
120
- Two-dimensional array suitable for the ``mask`` argument of
121
- ``wordcloud.WordCloud`` where ``0`` values define the drawable region.
122
-
123
- Raises
124
- ------
125
- ValueError
126
- If ``size`` or ``radius`` are non-positive.
127
- """
128
- if size <= 0:
129
- raise ValueError("size must be a positive integer.")
130
-
131
- resolved_radius = radius if radius is not None else size // 2
132
- if resolved_radius <= 0:
133
- raise ValueError("radius must be a positive integer.")
134
-
135
- center = (size - 1) / 2
136
- x, y = np.ogrid[:size, :size]
137
- mask_region = (x - center) ** 2 + (y - center) ** 2 > resolved_radius**2
138
- return 255 * mask_region.astype(np.uint8)
139
-
140
-
141
- def _plot_words(
142
- ax: Axes,
143
- words: Sequence[str],
144
- weights: Sequence[float],
145
- style: StyleTemplate,
146
- title: Optional[str],
147
- random_state: Optional[int],
148
- mask: Optional[np.ndarray],
149
- ) -> Axes:
150
- """Render words on the provided axes with sizes proportional to weights.
151
-
152
- Parameters
153
- ----------
154
- ax : matplotlib.axes.Axes
155
- Axes on which to draw.
156
- words : Sequence[str]
157
- Words to render.
158
- weights : Sequence[float]
159
- Corresponding weights for sizing.
160
- style : StyleTemplate
161
- Style configuration for the plot.
162
- title : str, optional
163
- Title of the plot. Defaults to ``None``.
164
- random_state : int, optional
165
- Seed for reproducible placement. Defaults to ``None``.
166
-
167
- Returns
168
- -------
169
- matplotlib.axes.Axes
170
- Axes containing the rendered word cloud.
171
- """
172
- ax.set_facecolor(style.background_color)
173
- ax.axis("off")
174
-
175
- if not words:
176
- if title:
177
- ax.set_title(title, color=style.font_color, fontsize=style.font_size * 1.5)
178
- return ax
179
-
180
- fig_obj = ax.get_figure()
181
- if not isinstance(fig_obj, Figure):
182
- raise RuntimeError("Axes is not associated with a Figure.")
183
-
184
- canvas = fig_obj.canvas
185
- if canvas is None:
186
- raise RuntimeError("Figure does not have an attached canvas.")
187
-
188
- canvas.draw()
189
- ax_bbox = ax.get_window_extent()
190
-
191
- if mask is None:
192
- mask_dimension = max(int(ax_bbox.width), int(ax_bbox.height), 1)
193
- resolved_mask = create_circular_mask(size=mask_dimension)
194
- else:
195
- resolved_mask = np.asarray(mask)
196
-
197
- if resolved_mask.ndim != 2:
198
- raise ValueError("mask must be a 2D array.")
199
-
200
- height, width = resolved_mask.shape
201
-
202
- frequency_map = {
203
- string_formatter(word): weight for word, weight in zip(words, weights)
204
- }
205
- min_font_size = style.font_mapping[min(style.font_mapping.keys())]
206
- max_font_size = style.font_mapping[max(style.font_mapping.keys())]
207
-
208
- wc = WordCloud(
209
- width=width,
210
- height=height,
211
- background_color=style.background_color,
212
- colormap=colormaps.get_cmap(style.palette),
213
- min_font_size=min_font_size,
214
- max_font_size=max_font_size,
215
- random_state=random_state,
216
- mask=resolved_mask,
217
- ).generate_from_frequencies(frequency_map)
218
-
219
- ax.imshow(wc.to_array(), interpolation="bilinear")
220
-
221
- if title:
222
- ax.set_title(title, color=style.font_color, fontsize=style.font_size * 1.5)
223
- return ax
224
-
225
-
226
- def aplot_wordcloud(
227
- pd_df: pd.DataFrame,
228
- text_column: str,
229
- weight_column: Optional[str] = None,
230
- title: Optional[str] = None,
231
- style: StyleTemplate = WORDCLOUD_STYLE_TEMPLATE,
232
- max_words: int = MAX_RESULTS,
233
- stopwords: Optional[Iterable[str]] = None,
234
- random_state: Optional[int] = None,
235
- ax: Optional[Axes | np.ndarray[Any, np.dtype[Any]]] = None,
236
- mask: Optional[np.ndarray] = None,
237
- ) -> Axes:
238
- """Plot a word cloud on the provided axes.
239
-
240
- Parameters
241
- ----------
242
- pd_df : pandas.DataFrame
243
- DataFrame containing the words to visualize.
244
- text_column : str
245
- Column containing words or phrases.
246
- weight_column : str, optional
247
- Column containing numeric weights. Defaults to ``None`` for equal weights.
248
- title : str, optional
249
- Plot title. Defaults to ``None``.
250
- style : StyleTemplate, optional
251
- Styling options. Defaults to ``WORDCLOUD_STYLE_TEMPLATE``.
252
- max_words : int, optional
253
- Maximum number of words to display. Defaults to ``MAX_RESULTS``.
254
- stopwords : Iterable[str], optional
255
- Words to exclude from the visualization. Defaults to ``None``.
256
- random_state : int, optional
257
- Seed for word placement. Defaults to ``None``.
258
- ax : matplotlib.axes.Axes or numpy.ndarray, optional
259
- Axes to draw on. Defaults to ``None`` which uses the current axes.
260
- mask : numpy.ndarray, optional
261
- Two-dimensional mask array defining the drawable region of the word cloud.
262
- Defaults to a circular mask generated by :func:`create_circular_mask`.
263
-
264
- Returns
265
- -------
266
- matplotlib.axes.Axes
267
- Axes containing the rendered word cloud.
268
-
269
- Raises
270
- ------
271
- AttributeError
272
- If required columns are missing from the DataFrame.
273
- TypeError
274
- If ``ax`` is not a ``matplotlib.axes.Axes`` instance.
275
- """
276
- if ax is None:
277
- ax = cast(Axes, plt.gca())
278
- elif isinstance(ax, np.ndarray):
279
- raise TypeError("ax must be a single matplotlib Axes instance, not an array.")
280
- elif not isinstance(ax, Axes):
281
- raise TypeError("ax must be a matplotlib Axes instance.")
282
-
283
- words, weights = _prepare_word_frequencies(
284
- pd_df=pd_df,
285
- text_column=text_column,
286
- weight_column=weight_column,
287
- max_words=max_words,
288
- stopwords=stopwords,
289
- )
290
- return _plot_words(
291
- ax,
292
- words,
293
- weights,
294
- style=style,
295
- title=title,
296
- random_state=random_state,
297
- mask=mask,
298
- )
299
-
300
-
301
- def fplot_wordcloud(
302
- pd_df: pd.DataFrame,
303
- text_column: str,
304
- weight_column: Optional[str] = None,
305
- title: Optional[str] = None,
306
- style: StyleTemplate = WORDCLOUD_STYLE_TEMPLATE,
307
- max_words: int = MAX_RESULTS,
308
- stopwords: Optional[Iterable[str]] = None,
309
- random_state: Optional[int] = None,
310
- figsize: Tuple[float, float] = FIG_SIZE,
311
- save_path: Optional[str] = None,
312
- savefig_kwargs: Optional[Dict[str, Any]] = None,
313
- mask: Optional[np.ndarray] = None,
314
- ) -> Figure:
315
- """Create a new figure with a word cloud.
316
-
317
- Parameters
318
- ----------
319
- pd_df : pandas.DataFrame
320
- DataFrame containing the words to visualize.
321
- text_column : str
322
- Column containing words or phrases.
323
- weight_column : str, optional
324
- Column containing numeric weights. Defaults to ``None`` for equal weights.
325
- title : str, optional
326
- Plot title. Defaults to ``None``.
327
- style : StyleTemplate, optional
328
- Styling options. Defaults to ``WORDCLOUD_STYLE_TEMPLATE``.
329
- max_words : int, optional
330
- Maximum number of words to display. Defaults to ``MAX_RESULTS``.
331
- stopwords : Iterable[str], optional
332
- Words to exclude from the visualization. Defaults to ``None``.
333
- random_state : int, optional
334
- Seed for word placement. Defaults to ``None``.
335
- figsize : tuple of float, optional
336
- Figure size. Defaults to ``FIG_SIZE``.
337
- mask : numpy.ndarray, optional
338
- Two-dimensional mask array defining the drawable region of the word cloud.
339
- Defaults to a circular mask generated by :func:`create_circular_mask`.
340
-
341
- Returns
342
- -------
343
- matplotlib.figure.Figure
344
- Figure containing the rendered word cloud.
345
-
346
- Raises
347
- ------
348
- AttributeError
349
- If required columns are missing from the DataFrame.
350
- """
351
- fig_raw, ax_raw = plt.subplots(figsize=figsize)
352
- fig = cast(Figure, fig_raw)
353
- ax = cast(Axes, ax_raw)
354
-
355
- _plot_words(
356
- ax,
357
- *_prepare_word_frequencies(
358
- pd_df=pd_df,
359
- text_column=text_column,
360
- weight_column=weight_column,
361
- max_words=max_words,
362
- stopwords=stopwords,
363
- ),
364
- style=style,
365
- title=title,
366
- random_state=random_state,
367
- mask=mask,
368
- )
369
- fig.patch.set_facecolor(style.background_color)
370
- fig.tight_layout()
371
- if save_path:
372
- fig.savefig(save_path, **(savefig_kwargs or {}))
373
- return fig
MatplotLibAPI/_typing.py DELETED
@@ -1,17 +0,0 @@
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
- ]
@@ -1,26 +0,0 @@
1
- MatplotLibAPI/Area.py,sha256=Y-tk6Di3Foj3yOGVbbOwDnPtL9rDh-VV2XTeaZcybgk,2095
2
- MatplotLibAPI/Bar.py,sha256=Y8mP_UWyU2h5T38L7j-Vnt0t9WSeCbV6Gw_-_48x3Bw,2243
3
- MatplotLibAPI/BoxViolin.py,sha256=8nnXGyDwrjiNJOiJHEYEcJMqD6JIF5JT8aZ0y4AXgLY,2008
4
- MatplotLibAPI/Bubble.py,sha256=y_1yM38u3k0yZ812oISZ8iUNwn93urWxdJKgcAFpIxs,12820
5
- MatplotLibAPI/Composite.py,sha256=JQo5ogTlcUlODCxojo3Wsx5ey1cqUIlBFylqysxx48I,9404
6
- MatplotLibAPI/Heatmap.py,sha256=SRT8pCKtEaJ1PivxxzCuXp-OBu4ljno2PGB_XXvFxzY,3369
7
- MatplotLibAPI/Histogram.py,sha256=znkQAVOa2-DMIKopCl_3-8JpDtymfGm4Bi4IyNXSVqs,1869
8
- MatplotLibAPI/Network.py,sha256=9jrkLCR4GQwOuDUqKFjQsytPl0nNInygHWoB-QTfw4Y,31699
9
- MatplotLibAPI/Pie.py,sha256=p0JuSP8h3TflEuvmGpPqNHO7hbAnse8hmMWBiZtzfsE,1882
10
- MatplotLibAPI/Pivot.py,sha256=6qH8e6U1TzUQcAIBmA_KMuHER2Uxp0-GFtwy9eJuS9A,3403
11
- MatplotLibAPI/Sankey.py,sha256=SpijCISghlsLqPuaWvnBP6vB-CV9k7FUGUi5LC6bKVc,1501
12
- MatplotLibAPI/StyleTemplate.py,sha256=Y3sBbUMbfAuxaONW8YixaI0UGgC7b1xnUo0MUMV4Z98,8176
13
- MatplotLibAPI/Sunburst.py,sha256=kqjEruXDDeuJpUKqbMw_VdT7fY0O4qzUNsIuwaTamdc,2584
14
- MatplotLibAPI/Table.py,sha256=6f8t4JUQ-owpd4fRL74Y0ovYFQO-SabStFXOqG48EoA,6450
15
- MatplotLibAPI/Timeserie.py,sha256=TGtshXXEwYEomxRCSb1MGzTTcgqk-M_GbQImVVP6RvE,10204
16
- MatplotLibAPI/Treemap.py,sha256=VBBk6MpNXoQtnxFzR1YPhIx6Lz9b7yJNHBMbQDhvefM,4848
17
- MatplotLibAPI/Waffle.py,sha256=uplRhUBDWUhSwPnI_GzU1O2D_RQXW_0OJ51m01PFKLg,2517
18
- MatplotLibAPI/Wordcloud.py,sha256=HqY-wA-VR3OGP1-OaI5Cqc0lS3WLnY9NkYD6QxePAXA,11447
19
- MatplotLibAPI/__init__.py,sha256=1-XM-PqzNwvkJvtpPV1x21zjEgjonVxaftXPMRrWxOo,2375
20
- MatplotLibAPI/_typing.py,sha256=Or3IPNceWKdyEk3CGXJb09FZR_fvT732oF0iWrx1ex8,598
21
- MatplotLibAPI/_visualization_utils.py,sha256=qIv7c0Mi3qK-saGxmKngw23uWxKFSAYjiH3uYTSr5Po,2215
22
- MatplotLibAPI/accessor.py,sha256=gYICR1qrm-R6scjuiJFMdXPd0164evQc8wGrjE7kOrk,52940
23
- matplotlibapi-3.2.21.dist-info/METADATA,sha256=TlfDACO70teDw4h-_md1EOo30dBKiU7V6tJ79pWqlJQ,5888
24
- matplotlibapi-3.2.21.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
25
- matplotlibapi-3.2.21.dist-info/licenses/LICENSE,sha256=hMErKLb6YZR3lRR5zr-vxeFkvY69QAaafgSpZ5-P1dQ,1067
26
- matplotlibapi-3.2.21.dist-info/RECORD,,