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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Histogram and KDE plotting helpers."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from pandas.api.extensions import register_dataframe_accessor
|
|
7
|
+
import seaborn as sns
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
from matplotlib.axes import Axes
|
|
10
|
+
from matplotlib.figure import Figure
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
from .base_plot import BasePlot
|
|
14
|
+
|
|
15
|
+
from .style_template import (
|
|
16
|
+
DISTRIBUTION_STYLE_TEMPLATE,
|
|
17
|
+
NETWORK_STYLE_TEMPLATE,
|
|
18
|
+
StyleTemplate,
|
|
19
|
+
string_formatter,
|
|
20
|
+
validate_dataframe,
|
|
21
|
+
)
|
|
22
|
+
from .utils import _get_axis
|
|
23
|
+
|
|
24
|
+
__all__ = ["DISTRIBUTION_STYLE_TEMPLATE", "aplot_histogram", "fplot_histogram"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@register_dataframe_accessor("histogram")
|
|
28
|
+
class Histogram(BasePlot):
|
|
29
|
+
"""Class for plotting histograms with optional KDE."""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
pd_df: pd.DataFrame,
|
|
34
|
+
column: str,
|
|
35
|
+
bins: int = 20,
|
|
36
|
+
kde: bool = True,
|
|
37
|
+
):
|
|
38
|
+
super().__init__(pd_df=pd_df)
|
|
39
|
+
self.column = column
|
|
40
|
+
self.bins = bins
|
|
41
|
+
self.kde = kde
|
|
42
|
+
|
|
43
|
+
def aplot(
|
|
44
|
+
self,
|
|
45
|
+
title: Optional[str] = None,
|
|
46
|
+
style: StyleTemplate = NETWORK_STYLE_TEMPLATE,
|
|
47
|
+
ax: Optional[Axes] = None,
|
|
48
|
+
**kwargs: Any,
|
|
49
|
+
) -> Axes:
|
|
50
|
+
|
|
51
|
+
validate_dataframe(self._obj, cols=[self.column])
|
|
52
|
+
plot_ax = _get_axis(ax)
|
|
53
|
+
sns.histplot(
|
|
54
|
+
data=self._obj,
|
|
55
|
+
x=self.column,
|
|
56
|
+
bins=self.bins,
|
|
57
|
+
kde=self.kde,
|
|
58
|
+
color=style.font_color,
|
|
59
|
+
edgecolor=style.background_color,
|
|
60
|
+
ax=plot_ax,
|
|
61
|
+
)
|
|
62
|
+
plot_ax.set_facecolor(style.background_color)
|
|
63
|
+
plot_ax.set_xlabel(string_formatter(self.column))
|
|
64
|
+
plot_ax.set_ylabel("Frequency")
|
|
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 = NETWORK_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(
|
|
82
|
+
title=title,
|
|
83
|
+
style=style,
|
|
84
|
+
ax=ax,
|
|
85
|
+
)
|
|
86
|
+
return fig
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def aplot_histogram(
|
|
90
|
+
pd_df: pd.DataFrame,
|
|
91
|
+
column: str,
|
|
92
|
+
bins: int = 20,
|
|
93
|
+
kde: bool = True,
|
|
94
|
+
title: Optional[str] = None,
|
|
95
|
+
style: StyleTemplate = DISTRIBUTION_STYLE_TEMPLATE,
|
|
96
|
+
ax: Optional[Axes] = None,
|
|
97
|
+
**kwargs: Any,
|
|
98
|
+
) -> Axes:
|
|
99
|
+
"""Plot a histogram with an optional kernel density estimate.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
pd_df : pd.DataFrame
|
|
104
|
+
The input DataFrame containing the data to plot.
|
|
105
|
+
column : str
|
|
106
|
+
The name of the column to plot.
|
|
107
|
+
bins : int, optional
|
|
108
|
+
The number of bins for the histogram, by default 20.
|
|
109
|
+
kde : bool, optional
|
|
110
|
+
Whether to include a kernel density estimate, by default True.
|
|
111
|
+
title : Optional[str], optional
|
|
112
|
+
The title of the plot, by default None.
|
|
113
|
+
style : StyleTemplate, optional
|
|
114
|
+
The style template to use for the plot, by default DISTRIBUTION_STYLE_TEMPLATE.
|
|
115
|
+
ax : Optional[Axes], optional
|
|
116
|
+
An optional matplotlib Axes to plot on. If None, a new figure and axes will be created, by default None.
|
|
117
|
+
**kwargs : Any
|
|
118
|
+
Additional keyword arguments to pass to seaborn.histplot.
|
|
119
|
+
"""
|
|
120
|
+
return Histogram(
|
|
121
|
+
pd_df=pd_df,
|
|
122
|
+
column=column,
|
|
123
|
+
bins=bins,
|
|
124
|
+
kde=kde,
|
|
125
|
+
).aplot(
|
|
126
|
+
title=title,
|
|
127
|
+
style=style,
|
|
128
|
+
ax=ax,
|
|
129
|
+
**kwargs,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def fplot_histogram(
|
|
134
|
+
pd_df: pd.DataFrame,
|
|
135
|
+
column: str,
|
|
136
|
+
bins: int = 20,
|
|
137
|
+
kde: bool = True,
|
|
138
|
+
title: Optional[str] = None,
|
|
139
|
+
style: StyleTemplate = DISTRIBUTION_STYLE_TEMPLATE,
|
|
140
|
+
figsize: Tuple[float, float] = (10, 6),
|
|
141
|
+
) -> Figure:
|
|
142
|
+
"""Plot a histogram with optional KDE on a new figure.
|
|
143
|
+
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
pd_df : pd.DataFrame
|
|
147
|
+
The input DataFrame containing the data to plot.
|
|
148
|
+
column : str
|
|
149
|
+
The name of the column to plot.
|
|
150
|
+
bins : int, optional
|
|
151
|
+
The number of bins for the histogram, by default 20.
|
|
152
|
+
kde : bool, optional
|
|
153
|
+
Whether to include a kernel density estimate, by default True.
|
|
154
|
+
title : Optional[str], optional
|
|
155
|
+
The title of the plot, by default None.
|
|
156
|
+
style : StyleTemplate, optional
|
|
157
|
+
The style template to use for the plot, by default DISTRIBUTION_STYLE_TEMPLATE.
|
|
158
|
+
figsize : Tuple[float, float], optional
|
|
159
|
+
The size of the figure, by default (10, 6).
|
|
160
|
+
"""
|
|
161
|
+
return Histogram(
|
|
162
|
+
pd_df=pd_df,
|
|
163
|
+
column=column,
|
|
164
|
+
bins=bins,
|
|
165
|
+
kde=kde,
|
|
166
|
+
).fplot(
|
|
167
|
+
title=title,
|
|
168
|
+
style=style,
|
|
169
|
+
figsize=figsize,
|
|
170
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""MCP helper utilities for MatplotLibAPI."""
|
|
2
|
+
|
|
3
|
+
from .metadata import (
|
|
4
|
+
DEDICATED_PLOT_TOOLS,
|
|
5
|
+
PLOT_MODULE_PARAMETER_HINTS,
|
|
6
|
+
SHARED_INPUT_CONTRACT,
|
|
7
|
+
)
|
|
8
|
+
from .renderers import MATPLOTLIB_RENDERERS, PLOTLY_RENDERERS, SUPPORTED_PLOT_MODULES
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"DEDICATED_PLOT_TOOLS",
|
|
12
|
+
"MATPLOTLIB_RENDERERS",
|
|
13
|
+
"PLOTLY_RENDERERS",
|
|
14
|
+
"PLOT_MODULE_PARAMETER_HINTS",
|
|
15
|
+
"SHARED_INPUT_CONTRACT",
|
|
16
|
+
"SUPPORTED_PLOT_MODULES",
|
|
17
|
+
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Discoverability metadata used by MCP plot tools."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
SHARED_INPUT_CONTRACT: Dict[str, str] = {
|
|
6
|
+
"csv_path": "Path to a CSV file with source data.",
|
|
7
|
+
"table": "In-memory table as list[dict[str, Any]] records.",
|
|
8
|
+
"return": "PNG bytes suitable for application/octet-stream.",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
PLOT_MODULE_PARAMETER_HINTS: Dict[str, Dict[str, str]] = {
|
|
12
|
+
"bubble": {
|
|
13
|
+
"label": "Bubble label column name.",
|
|
14
|
+
"x": "X-axis column name.",
|
|
15
|
+
"y": "Y-axis column name.",
|
|
16
|
+
"z": "Bubble size column name.",
|
|
17
|
+
},
|
|
18
|
+
"network": {
|
|
19
|
+
"edge_source_col": "Source-node column name (default: source).",
|
|
20
|
+
"edge_target_col": "Target-node column name (default: target).",
|
|
21
|
+
"edge_weight_col": "Edge-weight column name (default: weight).",
|
|
22
|
+
},
|
|
23
|
+
"bar": {
|
|
24
|
+
"category": "Category column name.",
|
|
25
|
+
"value": "Numeric value column name.",
|
|
26
|
+
},
|
|
27
|
+
"histogram": {"value": "Numeric value column name."},
|
|
28
|
+
"box_violin": {"y": "Numeric value column name."},
|
|
29
|
+
"heatmap": {
|
|
30
|
+
"x": "X-axis category column name.",
|
|
31
|
+
"y": "Y-axis category column name.",
|
|
32
|
+
"value": "Cell value column name.",
|
|
33
|
+
},
|
|
34
|
+
"correlation_matrix": {
|
|
35
|
+
"features": "List of numeric columns used in correlation matrix.",
|
|
36
|
+
},
|
|
37
|
+
"area": {
|
|
38
|
+
"x": "X-axis column name.",
|
|
39
|
+
"y": "List of stacked y-axis columns.",
|
|
40
|
+
},
|
|
41
|
+
"pie": {
|
|
42
|
+
"label": "Category label column name.",
|
|
43
|
+
"value": "Numeric value column name.",
|
|
44
|
+
},
|
|
45
|
+
"waffle": {
|
|
46
|
+
"label": "Category label column name.",
|
|
47
|
+
"value": "Numeric value column name.",
|
|
48
|
+
},
|
|
49
|
+
"sankey": {
|
|
50
|
+
"source": "Source-node column name.",
|
|
51
|
+
"target": "Target-node column name.",
|
|
52
|
+
"value": "Flow/weight column name.",
|
|
53
|
+
},
|
|
54
|
+
"table": {},
|
|
55
|
+
"timeserie": {
|
|
56
|
+
"x": "Datetime or ordered x-axis column name.",
|
|
57
|
+
"y": "List of y-axis series columns.",
|
|
58
|
+
},
|
|
59
|
+
"wordcloud": {
|
|
60
|
+
"text_column": "Text/token column name.",
|
|
61
|
+
"weight_column": "Weight/frequency column name (optional).",
|
|
62
|
+
},
|
|
63
|
+
"treemap": {
|
|
64
|
+
"path": "Hierarchy column names in order.",
|
|
65
|
+
"values": "Numeric value column name.",
|
|
66
|
+
},
|
|
67
|
+
"sunburst": {
|
|
68
|
+
"path": "Hierarchy column names in order.",
|
|
69
|
+
"values": "Numeric value column name.",
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
DEDICATED_PLOT_TOOLS: Dict[str, str] = {
|
|
74
|
+
"plot_bubble": "bubble",
|
|
75
|
+
"plot_network": "network",
|
|
76
|
+
"plot_bar": "bar",
|
|
77
|
+
"plot_histogram": "histogram",
|
|
78
|
+
"plot_box_violin": "box_violin",
|
|
79
|
+
"plot_heatmap": "heatmap",
|
|
80
|
+
"plot_correlation_matrix": "correlation_matrix",
|
|
81
|
+
"plot_area": "area",
|
|
82
|
+
"plot_pie": "pie",
|
|
83
|
+
"plot_waffle": "waffle",
|
|
84
|
+
"plot_sankey": "sankey",
|
|
85
|
+
"plot_table": "table",
|
|
86
|
+
"plot_timeserie": "timeserie",
|
|
87
|
+
"plot_wordcloud": "wordcloud",
|
|
88
|
+
"plot_treemap": "treemap",
|
|
89
|
+
"plot_sunburst": "sunburst",
|
|
90
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Renderer registries for MCP plot-module dispatch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Callable, Dict
|
|
6
|
+
|
|
7
|
+
from ..area import fplot_area
|
|
8
|
+
from ..bar import fplot_bar
|
|
9
|
+
from ..box_violin import fplot_box_violin
|
|
10
|
+
from ..heatmap import fplot_correlation_matrix, fplot_heatmap
|
|
11
|
+
from ..histogram import fplot_histogram
|
|
12
|
+
from ..pie import fplot_pie
|
|
13
|
+
from ..sankey import fplot_sankey
|
|
14
|
+
from ..sunburst import fplot_sunburst
|
|
15
|
+
from ..table import fplot_table
|
|
16
|
+
from ..timeserie import fplot_timeserie
|
|
17
|
+
from ..treemap import fplot_treemap
|
|
18
|
+
from ..waffle import fplot_waffle
|
|
19
|
+
from ..word_cloud import fplot_wordcloud
|
|
20
|
+
|
|
21
|
+
Renderer = Callable[..., Any]
|
|
22
|
+
|
|
23
|
+
MATPLOTLIB_RENDERERS: Dict[str, Renderer] = {
|
|
24
|
+
"bar": fplot_bar,
|
|
25
|
+
"histogram": fplot_histogram,
|
|
26
|
+
"box_violin": fplot_box_violin,
|
|
27
|
+
"heatmap": fplot_heatmap,
|
|
28
|
+
"correlation_matrix": fplot_correlation_matrix,
|
|
29
|
+
"area": fplot_area,
|
|
30
|
+
"pie": fplot_pie,
|
|
31
|
+
"waffle": fplot_waffle,
|
|
32
|
+
"table": fplot_table,
|
|
33
|
+
"timeserie": fplot_timeserie,
|
|
34
|
+
"wordcloud": fplot_wordcloud,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
PLOTLY_RENDERERS: Dict[str, Renderer] = {
|
|
38
|
+
"sankey": fplot_sankey,
|
|
39
|
+
"treemap": fplot_treemap,
|
|
40
|
+
"sunburst": fplot_sunburst,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
SUPPORTED_PLOT_MODULES = sorted(
|
|
44
|
+
["bubble", "network", *MATPLOTLIB_RENDERERS.keys(), *PLOTLY_RENDERERS.keys()]
|
|
45
|
+
)
|