MatplotLibAPI 3.3.0__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 (49) hide show
  1. MatplotLibAPI/__init__.py +4 -86
  2. MatplotLibAPI/accessor.py +279 -182
  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} +70 -83
  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.py → network/core.py} +346 -809
  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} +8 -4
  24. MatplotLibAPI/sunburst.py +139 -0
  25. MatplotLibAPI/{Table.py → table.py} +108 -93
  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/{Wordcloud.py → word_cloud.py} +187 -88
  32. {matplotlibapi-3.3.0.dist-info → matplotlibapi-4.0.0.dist-info}/METADATA +98 -9
  33. matplotlibapi-4.0.0.dist-info/RECORD +36 -0
  34. {matplotlibapi-3.3.0.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 -460
  40. MatplotLibAPI/Heatmap.py +0 -121
  41. MatplotLibAPI/Histogram.py +0 -73
  42. MatplotLibAPI/Pie.py +0 -70
  43. MatplotLibAPI/Pivot.py +0 -134
  44. MatplotLibAPI/Sankey.py +0 -46
  45. MatplotLibAPI/Sunburst.py +0 -89
  46. MatplotLibAPI/Waffle.py +0 -86
  47. MatplotLibAPI/_typing.py +0 -17
  48. matplotlibapi-3.3.0.dist-info/RECORD +0 -26
  49. {matplotlibapi-3.3.0.dist-info → matplotlibapi-4.0.0.dist-info}/licenses/LICENSE +0 -0
MatplotLibAPI/Pie.py DELETED
@@ -1,70 +0,0 @@
1
- """Pie and donut chart helpers."""
2
-
3
- from typing import Any, Dict, Optional, Tuple
4
-
5
- import matplotlib.pyplot as plt
6
- import pandas as pd
7
- import seaborn as sns
8
- from matplotlib.axes import Axes
9
- from matplotlib.figure import Figure
10
-
11
- from .StyleTemplate import PIE_STYLE_TEMPLATE, StyleTemplate, validate_dataframe
12
- from ._visualization_utils import _get_axis, _wrap_aplot
13
-
14
-
15
- def aplot_pie_donut(
16
- pd_df: pd.DataFrame,
17
- category: str,
18
- value: str,
19
- donut: bool = False,
20
- title: Optional[str] = None,
21
- style: StyleTemplate = PIE_STYLE_TEMPLATE,
22
- ax: Optional[Axes] = None,
23
- **kwargs: Any,
24
- ) -> Axes:
25
- """Plot pie or donut charts for categorical share visualization."""
26
- validate_dataframe(pd_df, cols=[category, value])
27
- plot_ax = _get_axis(ax)
28
- labels = pd_df[category].astype(str).tolist()
29
- sizes = pd_df[value]
30
-
31
- wedgeprops: Optional[Dict[str, Any]] = None
32
- if donut:
33
- wedgeprops = {"width": 0.3}
34
- wedges, *_ = plot_ax.pie(
35
- sizes,
36
- labels=labels,
37
- autopct="%1.1f%%",
38
- colors=sns.color_palette(style.palette),
39
- wedgeprops=wedgeprops,
40
- )
41
- plot_ax.axis("equal")
42
- if title:
43
- plot_ax.set_title(title)
44
- return plot_ax
45
-
46
-
47
- def fplot_pie_donut(
48
- pd_df: pd.DataFrame,
49
- category: str,
50
- value: str,
51
- donut: bool = False,
52
- title: Optional[str] = None,
53
- style: StyleTemplate = PIE_STYLE_TEMPLATE,
54
- figsize: Tuple[float, float] = (8, 8),
55
- save_path: Optional[str] = None,
56
- savefig_kwargs: Optional[Dict[str, Any]] = None,
57
- ) -> Figure:
58
- """Plot pie or donut charts on a new figure."""
59
- return _wrap_aplot(
60
- aplot_pie_donut,
61
- pd_df=pd_df,
62
- figsize=figsize,
63
- category=category,
64
- value=value,
65
- donut=donut,
66
- title=title,
67
- style=style,
68
- save_path=save_path,
69
- savefig_kwargs=savefig_kwargs,
70
- )
MatplotLibAPI/Pivot.py DELETED
@@ -1,134 +0,0 @@
1
- """Pivot chart helpers for bar and line plots."""
2
-
3
- from typing import Optional, cast
4
-
5
- import matplotlib.pyplot as plt
6
- import pandas as pd
7
- from matplotlib.axes import Axes
8
-
9
- from .StyleTemplate import (
10
- PIVOTBARS_STYLE_TEMPLATE,
11
- PIVOTLINES_STYLE_TEMPLATE,
12
- StyleTemplate,
13
- format_func,
14
- string_formatter,
15
- validate_dataframe,
16
- )
17
-
18
-
19
- def _pivot_and_sort_data(
20
- data: pd.DataFrame,
21
- index: str,
22
- columns: str,
23
- values: str,
24
- aggfunc: str = "sum",
25
- sort_by: Optional[str] = None,
26
- ascending: bool = False,
27
- ) -> pd.DataFrame:
28
- """Pivot and sort a DataFrame.
29
-
30
- Parameters
31
- ----------
32
- data : pd.DataFrame
33
- The input DataFrame.
34
- index : str
35
- The column to use as the pivot table index.
36
- columns : str
37
- The column to use for pivot table columns.
38
- values : str
39
- The column to aggregate.
40
- aggfunc : str, optional
41
- The aggregation function, by default "sum".
42
- sort_by : str, optional
43
- The column to sort by.
44
- ascending : bool, optional
45
- The sort order, by default `False`.
46
-
47
- Returns
48
- -------
49
- pd.DataFrame
50
- A pivoted and sorted DataFrame.
51
- """
52
- pivot_df = pd.pivot_table(
53
- data, values=values, index=[index], columns=[columns], aggfunc=aggfunc
54
- )
55
- if sort_by:
56
- pivot_df = pivot_df.sort_values(by=sort_by, ascending=ascending)
57
- return pivot_df.reset_index()
58
-
59
-
60
- def plot_pivoted_bars(
61
- data: pd.DataFrame,
62
- label: str,
63
- x: str,
64
- y: str,
65
- agg: str = "sum",
66
- style: StyleTemplate = PIVOTBARS_STYLE_TEMPLATE,
67
- title: Optional[str] = None,
68
- sort_by: Optional[str] = None,
69
- ascending: bool = False,
70
- ax: Optional[Axes] = None,
71
- stacked: bool = False,
72
- ) -> Axes:
73
- """Plot a bar chart from a pivot table.
74
-
75
- Parameters
76
- ----------
77
- data : pd.DataFrame
78
- The DataFrame containing the data to plot.
79
- label : str
80
- The column to pivot into series.
81
- x : str
82
- The column for the x-axis.
83
- y : str
84
- The column for the y-values.
85
- agg : str, optional
86
- The aggregation function for the pivot. The default is "sum".
87
- style : StyleTemplate, optional
88
- The style configuration. The default is `PIVOTBARS_STYLE_TEMPLATE`.
89
- title : str, optional
90
- The plot title.
91
- sort_by : str, optional
92
- The column to sort by.
93
- ascending : bool, optional
94
- The sort order. The default is `False`.
95
- ax : Axes, optional
96
- The axes to draw on.
97
- stacked : bool, optional
98
- Whether to stack the bars. The default is `False`.
99
-
100
- Returns
101
- -------
102
- Axes
103
- The matplotlib axes with the bar chart.
104
- """
105
- validate_dataframe(data, cols=[label, x, y], sort_by=sort_by)
106
-
107
- pivot_df = _pivot_and_sort_data(
108
- data,
109
- index=x,
110
- columns=label,
111
- values=y,
112
- aggfunc=agg,
113
- sort_by=sort_by,
114
- ascending=ascending,
115
- )
116
-
117
- if ax is None:
118
- ax = cast(Axes, plt.gca())
119
-
120
- pivot_df.plot(kind="bar", x=x, stacked=stacked, ax=ax, alpha=0.7)
121
-
122
- ax.set_ylabel(string_formatter(y))
123
- ax.set_xlabel(string_formatter(x))
124
- if title:
125
- ax.set_title(title)
126
-
127
- ax.legend(
128
- fontsize=style.font_size - 2,
129
- title_fontsize=style.font_size + 2,
130
- labelcolor="linecolor",
131
- facecolor=style.background_color,
132
- )
133
- ax.tick_params(axis="x", rotation=90)
134
- return ax
MatplotLibAPI/Sankey.py DELETED
@@ -1,46 +0,0 @@
1
- """Sankey plotting helpers."""
2
-
3
- from typing import Any, Dict, List, Optional
4
-
5
- import pandas as pd
6
- import plotly.graph_objects as go
7
-
8
- from .StyleTemplate import SANKEY_STYLE_TEMPLATE, StyleTemplate, validate_dataframe
9
-
10
-
11
- def fplot_sankey(
12
- pd_df: pd.DataFrame,
13
- source: str,
14
- target: str,
15
- value: str,
16
- title: Optional[str] = None,
17
- style: StyleTemplate = SANKEY_STYLE_TEMPLATE,
18
- save_path: Optional[str] = None,
19
- savefig_kwargs: Optional[Dict[str, Any]] = None,
20
- ) -> go.Figure:
21
- """Plot a Sankey diagram showing flows between categories."""
22
- validate_dataframe(pd_df, cols=[source, target, value])
23
-
24
- labels: List[str] = list(pd.unique(pd.concat([pd_df[source], pd_df[target]])))
25
- label_to_index: Dict[str, int] = {name: idx for idx, name in enumerate(labels)}
26
-
27
- sankey = go.Sankey(
28
- node=dict(label=labels, pad=15, thickness=20, color=style.font_color),
29
- link=dict(
30
- source=[label_to_index[val] for val in pd_df[source]],
31
- target=[label_to_index[val] for val in pd_df[target]],
32
- value=pd_df[value],
33
- ),
34
- )
35
-
36
- fig = go.Figure(sankey)
37
- if title:
38
- fig.update_layout(
39
- title_text=title, font=dict(color=style.font_color, size=style.font_size)
40
- )
41
- if save_path:
42
- if save_path.lower().endswith((".html", ".htm")):
43
- fig.write_html(save_path, **(savefig_kwargs or {}))
44
- else:
45
- fig.write_image(save_path, **(savefig_kwargs or {}))
46
- return fig
MatplotLibAPI/Sunburst.py DELETED
@@ -1,89 +0,0 @@
1
- """Sunburst chart plotting utilities."""
2
-
3
- from typing import Any, Dict, Optional
4
-
5
- import pandas as pd
6
- import plotly.graph_objects as go
7
-
8
- from .StyleTemplate import (
9
- TREEMAP_STYLE_TEMPLATE,
10
- StyleTemplate,
11
- validate_dataframe,
12
- )
13
-
14
-
15
- def fplot_sunburst(
16
- pd_df: pd.DataFrame,
17
- labels: str,
18
- parents: str,
19
- values: str,
20
- style: StyleTemplate = TREEMAP_STYLE_TEMPLATE,
21
- title: Optional[str] = None,
22
- sort_by: Optional[str] = None,
23
- ascending: bool = False,
24
- max_values: int = 100,
25
- fig: Optional[go.Figure] = None,
26
- save_path: Optional[str] = None,
27
- savefig_kwargs: Optional[Dict[str, Any]] = None,
28
- ) -> go.Figure:
29
- """Return a figure containing the sunburst plot.
30
-
31
- Parameters
32
- ----------
33
- pd_df : pd.DataFrame
34
- DataFrame containing the data to plot.
35
- labels : str
36
- Column representing the labels of the sectors.
37
- parents : str
38
- Column representing the parent of each sector.
39
- values : str
40
- Column containing values for each sunburst sector.
41
- style : StyleTemplate, optional
42
- Style configuration. The default is `TREEMAP_STYLE_TEMPLATE`.
43
- title : str, optional
44
- Plot title.
45
- sort_by : str, optional
46
- Column used to sort data.
47
- ascending : bool, optional
48
- Sort order for the data. The default is `False`.
49
- max_values : int, optional
50
- Maximum number of rows to plot. The default is 100.
51
- fig : go.Figure, optional
52
- Existing figure to add the sunburst chart to.
53
-
54
- Returns
55
- -------
56
- go.Figure
57
- Figure containing the sunburst plot.
58
- """
59
- cols = [labels, parents, values]
60
- validate_dataframe(pd_df, cols=cols, sort_by=sort_by)
61
- if not sort_by:
62
- sort_by = values
63
- df = pd_df.sort_values(by=sort_by, ascending=ascending)[cols].head(max_values)
64
-
65
- trace = go.Sunburst(
66
- labels=df[labels],
67
- parents=df[parents],
68
- values=df[values],
69
- textinfo="label+percent entry",
70
- )
71
-
72
- if not fig:
73
- fig = go.Figure(trace)
74
- else:
75
- fig.add_trace(trace)
76
-
77
- fig.update_layout(
78
- title=title,
79
- plot_bgcolor=style.background_color,
80
- paper_bgcolor=style.background_color,
81
- font=dict(family=style.font_name, size=style.font_size, color=style.font_color),
82
- showlegend=style.legend if style else True,
83
- )
84
- if save_path:
85
- if save_path.lower().endswith((".html", ".htm")):
86
- fig.write_html(save_path, **(savefig_kwargs or {}))
87
- else:
88
- fig.write_image(save_path, **(savefig_kwargs or {}))
89
- return fig
MatplotLibAPI/Waffle.py DELETED
@@ -1,86 +0,0 @@
1
- """Waffle chart helpers."""
2
-
3
- from typing import Any, Dict, Optional, Tuple
4
-
5
- import pandas as pd
6
- import seaborn as sns
7
- from matplotlib.axes import Axes
8
- from matplotlib.figure import Figure
9
- from matplotlib.patches import Rectangle
10
- import matplotlib.pyplot as plt
11
-
12
- from .StyleTemplate import PIE_STYLE_TEMPLATE, StyleTemplate, validate_dataframe
13
- from ._visualization_utils import _get_axis, _wrap_aplot
14
-
15
-
16
- def aplot_waffle(
17
- pd_df: pd.DataFrame,
18
- category: str,
19
- value: str,
20
- rows: int = 10,
21
- title: Optional[str] = None,
22
- style: StyleTemplate = PIE_STYLE_TEMPLATE,
23
- ax: Optional[Axes] = None,
24
- **kwargs: Any,
25
- ) -> Axes:
26
- """Plot a simple waffle chart as a grid of proportional squares."""
27
- validate_dataframe(pd_df, cols=[category, value])
28
- plot_ax = _get_axis(ax)
29
- total = float(pd_df[value].sum())
30
- squares = rows * rows
31
- colors = sns.color_palette(style.palette, n_colors=len(pd_df))
32
- plot_ax.set_aspect("equal")
33
-
34
- start = 0
35
- for idx, (label, val) in enumerate(zip(pd_df[category], pd_df[value])):
36
- count = int(round((val / total) * squares))
37
- for square in range(start, min(start + count, squares)):
38
- row = square // rows
39
- col = square % rows
40
- plot_ax.add_patch(
41
- Rectangle(
42
- (col, rows - row),
43
- 1,
44
- 1,
45
- facecolor=colors[idx],
46
- edgecolor=style.background_color,
47
- )
48
- )
49
- start += count
50
-
51
- plot_ax.set_xlim(0, rows)
52
- plot_ax.set_ylim(0, rows + 1)
53
- plot_ax.axis("off")
54
- if title:
55
- plot_ax.set_title(title)
56
- legend_handles = [Rectangle((0, 0), 1, 1, color=color) for color in colors]
57
- plot_ax.legend(
58
- legend_handles, pd_df[category], loc="upper center", ncol=3, frameon=False
59
- )
60
- return plot_ax
61
-
62
-
63
- def fplot_waffle(
64
- pd_df: pd.DataFrame,
65
- category: str,
66
- value: str,
67
- rows: int = 10,
68
- title: Optional[str] = None,
69
- style: StyleTemplate = PIE_STYLE_TEMPLATE,
70
- figsize: Tuple[float, float] = (8, 8),
71
- save_path: Optional[str] = None,
72
- savefig_kwargs: Optional[Dict[str, Any]] = None,
73
- ) -> Figure:
74
- """Plot waffle charts on a new figure."""
75
- return _wrap_aplot(
76
- aplot_waffle,
77
- pd_df=pd_df,
78
- figsize=figsize,
79
- category=category,
80
- value=value,
81
- rows=rows,
82
- title=title,
83
- style=style,
84
- save_path=save_path,
85
- savefig_kwargs=savefig_kwargs,
86
- )
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=KvneYBrrGiGKuRyLjNDcOK-hUl_KwMaJKP_XO6Hx1jo,12844
5
- MatplotLibAPI/Composite.py,sha256=nsg1eAVf-6uzd4QrNNwp2sLCtCzeQ0d-DHHsEFeF6eY,10304
6
- MatplotLibAPI/Heatmap.py,sha256=SRT8pCKtEaJ1PivxxzCuXp-OBu4ljno2PGB_XXvFxzY,3369
7
- MatplotLibAPI/Histogram.py,sha256=znkQAVOa2-DMIKopCl_3-8JpDtymfGm4Bi4IyNXSVqs,1869
8
- MatplotLibAPI/Network.py,sha256=4ZyQlmy2v-AXWFJ2casfdQLwpL8JUcN7j2ZOOtUsTM0,62298
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=gO-Wj3akH3pc_Z1Dh2NPYKIZjmavhSHv53r_8dmsIgM,8356
13
- MatplotLibAPI/Sunburst.py,sha256=kqjEruXDDeuJpUKqbMw_VdT7fY0O4qzUNsIuwaTamdc,2584
14
- MatplotLibAPI/Table.py,sha256=CA4K772ByaSBc9toDXUojUJL2AzD-mEtTF7KPlFsp74,6559
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=AMzMdvGyWVaYTettvurJNxJxQvrUDe9Tj4X8LOpZVOk,12314
19
- MatplotLibAPI/__init__.py,sha256=PC1LkW3tbXluk5f_Zv2MqO1xppvdIl9AQEo9k7P5b4o,2365
20
- MatplotLibAPI/_typing.py,sha256=Or3IPNceWKdyEk3CGXJb09FZR_fvT732oF0iWrx1ex8,598
21
- MatplotLibAPI/_visualization_utils.py,sha256=qIv7c0Mi3qK-saGxmKngw23uWxKFSAYjiH3uYTSr5Po,2215
22
- MatplotLibAPI/accessor.py,sha256=rOvpQVg_3uds8f4EoiCfkBOzYPLuPwCC2jtCmFpwwNA,62042
23
- matplotlibapi-3.3.0.dist-info/METADATA,sha256=SZtMcfCN_V1nzgSIwRsB8Thdojj0E8ePm_3rVNuOfRs,5887
24
- matplotlibapi-3.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
25
- matplotlibapi-3.3.0.dist-info/licenses/LICENSE,sha256=hMErKLb6YZR3lRR5zr-vxeFkvY69QAaafgSpZ5-P1dQ,1067
26
- matplotlibapi-3.3.0.dist-info/RECORD,,