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,139 @@
|
|
|
1
|
+
"""Sunburst chart plotting utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
import plotly.graph_objects as go
|
|
9
|
+
|
|
10
|
+
from .style_template import (
|
|
11
|
+
TREEMAP_STYLE_TEMPLATE,
|
|
12
|
+
StyleTemplate,
|
|
13
|
+
validate_dataframe,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = ["TREEMAP_STYLE_TEMPLATE", "fplot_sunburst"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SunburstData:
|
|
20
|
+
labels: list[str]
|
|
21
|
+
parents: list[str]
|
|
22
|
+
values: list[float]
|
|
23
|
+
|
|
24
|
+
def __init__(self, labels: list[str], parents: list[str], values: list[float]):
|
|
25
|
+
self.labels = labels
|
|
26
|
+
self.parents = parents
|
|
27
|
+
self.values = values
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def from_pandas(
|
|
31
|
+
edges_df: pd.DataFrame,
|
|
32
|
+
labels_col: str,
|
|
33
|
+
parents_col: str,
|
|
34
|
+
values_col: str,
|
|
35
|
+
) -> "SunburstData":
|
|
36
|
+
"""Create ``SunburstData`` from a DataFrame.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
edges_df : pd.DataFrame
|
|
41
|
+
DataFrame containing the data to plot.
|
|
42
|
+
labels_col : str
|
|
43
|
+
Column representing the labels of the sectors.
|
|
44
|
+
parents_col : str
|
|
45
|
+
Column representing the parent of each sector.
|
|
46
|
+
values_col : str
|
|
47
|
+
Column containing values for each sunburst sector.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
SunburstData
|
|
52
|
+
SunburstData object containing the labels, parents, and values for the sunburst plot.
|
|
53
|
+
"""
|
|
54
|
+
validate_dataframe(edges_df, cols=[labels_col, parents_col, values_col])
|
|
55
|
+
return SunburstData(
|
|
56
|
+
labels=edges_df[labels_col].astype(str).tolist(),
|
|
57
|
+
parents=edges_df[parents_col].astype(str).tolist(),
|
|
58
|
+
values=edges_df[values_col].tolist(),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def fplot(
|
|
62
|
+
self,
|
|
63
|
+
style: StyleTemplate = TREEMAP_STYLE_TEMPLATE,
|
|
64
|
+
title: Optional[str] = None,
|
|
65
|
+
) -> go.Figure:
|
|
66
|
+
"""Return a figure containing the sunburst plot.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
style : StyleTemplate, optional
|
|
71
|
+
Style configuration. The default is `TREEMAP_STYLE_TEMPLATE`.
|
|
72
|
+
title : str, optional
|
|
73
|
+
Plot title.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
go.Figure
|
|
78
|
+
Figure containing the sunburst plot.
|
|
79
|
+
"""
|
|
80
|
+
trace = go.Sunburst(
|
|
81
|
+
labels=self.labels,
|
|
82
|
+
parents=self.parents,
|
|
83
|
+
values=self.values,
|
|
84
|
+
textinfo="label+percent entry",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
fig = go.Figure(trace)
|
|
88
|
+
|
|
89
|
+
fig.update_layout(
|
|
90
|
+
title=title,
|
|
91
|
+
plot_bgcolor=style.background_color,
|
|
92
|
+
paper_bgcolor=style.background_color,
|
|
93
|
+
font=dict(
|
|
94
|
+
family=style.font_name, size=style.font_size, color=style.font_color
|
|
95
|
+
),
|
|
96
|
+
showlegend=style.legend if style else True,
|
|
97
|
+
)
|
|
98
|
+
return fig
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def fplot_sunburst(
|
|
102
|
+
pd_df: pd.DataFrame,
|
|
103
|
+
labels: str,
|
|
104
|
+
parents: str,
|
|
105
|
+
values: str,
|
|
106
|
+
style: StyleTemplate = TREEMAP_STYLE_TEMPLATE,
|
|
107
|
+
title: Optional[str] = None,
|
|
108
|
+
) -> go.Figure:
|
|
109
|
+
"""Return a figure containing the sunburst plot.
|
|
110
|
+
|
|
111
|
+
Parameters
|
|
112
|
+
----------
|
|
113
|
+
pd_df : pd.DataFrame
|
|
114
|
+
DataFrame containing the data to plot.
|
|
115
|
+
labels : str
|
|
116
|
+
Column representing the labels of the sectors.
|
|
117
|
+
parents : str
|
|
118
|
+
Column representing the parent of each sector.
|
|
119
|
+
values : str
|
|
120
|
+
Column containing values for each sunburst sector.
|
|
121
|
+
style : StyleTemplate, optional
|
|
122
|
+
Style configuration. The default is `TREEMAP_STYLE_TEMPLATE`.
|
|
123
|
+
title : str, optional
|
|
124
|
+
Plot title.
|
|
125
|
+
|
|
126
|
+
Returns
|
|
127
|
+
-------
|
|
128
|
+
go.Figure
|
|
129
|
+
Figure containing the sunburst plot.
|
|
130
|
+
"""
|
|
131
|
+
return SunburstData.from_pandas(
|
|
132
|
+
edges_df=pd_df,
|
|
133
|
+
labels_col=labels,
|
|
134
|
+
parents_col=parents,
|
|
135
|
+
values_col=values,
|
|
136
|
+
).fplot(
|
|
137
|
+
style=style,
|
|
138
|
+
title=title,
|
|
139
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Table plotting helpers."""
|
|
2
2
|
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, List, Optional, Tuple
|
|
4
4
|
import pandas as pd
|
|
5
5
|
import matplotlib.pyplot as plt
|
|
6
6
|
from matplotlib.axes import Axes
|
|
@@ -8,65 +8,20 @@ from matplotlib.figure import Figure
|
|
|
8
8
|
from matplotlib.transforms import Bbox
|
|
9
9
|
from matplotlib.table import Table
|
|
10
10
|
|
|
11
|
-
from .
|
|
11
|
+
from .base_plot import BasePlot
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
background_color="black", fig_border="darkgrey", font_color="white", palette="magma"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def _prepare_table_data(
|
|
19
|
-
pd_df: pd.DataFrame,
|
|
20
|
-
cols: List[str],
|
|
21
|
-
sort_by: Optional[str],
|
|
22
|
-
ascending: bool,
|
|
23
|
-
max_values: int,
|
|
24
|
-
style: StyleTemplate,
|
|
25
|
-
) -> pd.DataFrame:
|
|
26
|
-
"""Prepare data for table plotting.
|
|
27
|
-
|
|
28
|
-
Parameters
|
|
29
|
-
----------
|
|
30
|
-
pd_df : pd.DataFrame
|
|
31
|
-
Input DataFrame.
|
|
32
|
-
cols : List[str]
|
|
33
|
-
Columns to include in the table.
|
|
34
|
-
sort_by : Optional[str]
|
|
35
|
-
Column to sort by.
|
|
36
|
-
ascending : bool
|
|
37
|
-
Sort order.
|
|
38
|
-
max_values : int
|
|
39
|
-
Maximum number of rows to display.
|
|
40
|
-
style : StyleTemplate
|
|
41
|
-
Styling for the plot.
|
|
42
|
-
|
|
43
|
-
Returns
|
|
44
|
-
-------
|
|
45
|
-
pd.DataFrame
|
|
46
|
-
Prepared DataFrame for plotting.
|
|
47
|
-
|
|
48
|
-
Raises
|
|
49
|
-
------
|
|
50
|
-
AttributeError
|
|
51
|
-
If required columns are missing from the DataFrame.
|
|
52
|
-
"""
|
|
53
|
-
validate_dataframe(pd_df, cols=cols, sort_by=sort_by)
|
|
13
|
+
from .utils import _get_axis
|
|
54
14
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
15
|
+
from .style_template import (
|
|
16
|
+
FIG_SIZE,
|
|
17
|
+
TITLE_SCALE_FACTOR,
|
|
18
|
+
TABLE_STYLE_TEMPLATE,
|
|
19
|
+
StyleTemplate,
|
|
20
|
+
string_formatter,
|
|
21
|
+
validate_dataframe,
|
|
22
|
+
)
|
|
64
23
|
|
|
65
|
-
|
|
66
|
-
for col, func in style.format_funcs.items():
|
|
67
|
-
if col in plot_df.columns and func is not None:
|
|
68
|
-
plot_df[col] = plot_df[col].apply(func)
|
|
69
|
-
return plot_df
|
|
24
|
+
__all__ = ["TABLE_STYLE_TEMPLATE", "aplot_table", "fplot_table"]
|
|
70
25
|
|
|
71
26
|
|
|
72
27
|
def _format_table(table: Table, style: StyleTemplate):
|
|
@@ -89,6 +44,89 @@ def _format_table(table: Table, style: StyleTemplate):
|
|
|
89
44
|
cell.get_text().set_color(style.font_color)
|
|
90
45
|
|
|
91
46
|
|
|
47
|
+
class TablePlot(BasePlot):
|
|
48
|
+
"""Class for plotting tables."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, pd_df: pd.DataFrame, cols: List[str]):
|
|
51
|
+
validate_dataframe(pd_df, cols=cols)
|
|
52
|
+
super().__init__(pd_df=pd_df)
|
|
53
|
+
self.cols = cols
|
|
54
|
+
|
|
55
|
+
def aplot(
|
|
56
|
+
self,
|
|
57
|
+
title: Optional[str] = None,
|
|
58
|
+
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
59
|
+
sort_by: Optional[str] = None,
|
|
60
|
+
ascending: bool = False,
|
|
61
|
+
max_values: int = 20,
|
|
62
|
+
ax: Optional[Axes] = None,
|
|
63
|
+
**kwargs: Any,
|
|
64
|
+
) -> Axes:
|
|
65
|
+
plot_ax = _get_axis(ax)
|
|
66
|
+
|
|
67
|
+
if sort_by is None:
|
|
68
|
+
sort_by = self.cols[0]
|
|
69
|
+
|
|
70
|
+
plot_df = (
|
|
71
|
+
self._obj[self.cols]
|
|
72
|
+
.sort_values(by=[sort_by], ascending=ascending) # type: ignore
|
|
73
|
+
.head(max_values)
|
|
74
|
+
.copy()
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if style.format_funcs:
|
|
78
|
+
for col, func in style.format_funcs.items():
|
|
79
|
+
if col in plot_df.columns and func is not None:
|
|
80
|
+
plot_df[col] = plot_df[col].apply(func)
|
|
81
|
+
|
|
82
|
+
table_plot = plot_ax.table(
|
|
83
|
+
cellText=plot_df.values.tolist(),
|
|
84
|
+
colLabels=[string_formatter(colLabel) for colLabel in self.cols],
|
|
85
|
+
cellLoc="center",
|
|
86
|
+
colWidths=style.col_widths,
|
|
87
|
+
bbox=Bbox.from_bounds(0, -0.3, 1, 1.3),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
_format_table(table_plot, style)
|
|
91
|
+
|
|
92
|
+
plot_ax.set_facecolor(style.background_color)
|
|
93
|
+
plot_ax.set_axis_off()
|
|
94
|
+
plot_ax.grid(False)
|
|
95
|
+
if title:
|
|
96
|
+
plot_ax.set_title(
|
|
97
|
+
title,
|
|
98
|
+
color=style.font_color,
|
|
99
|
+
fontsize=style.font_size * TITLE_SCALE_FACTOR,
|
|
100
|
+
)
|
|
101
|
+
plot_ax.title.set_position((0.5, 1.05))
|
|
102
|
+
return plot_ax
|
|
103
|
+
|
|
104
|
+
def fplot(
|
|
105
|
+
self,
|
|
106
|
+
title: Optional[str] = None,
|
|
107
|
+
style: StyleTemplate = TABLE_STYLE_TEMPLATE,
|
|
108
|
+
sort_by: Optional[str] = None,
|
|
109
|
+
ascending: bool = False,
|
|
110
|
+
max_values: int = 20,
|
|
111
|
+
figsize: Tuple[float, float] = FIG_SIZE,
|
|
112
|
+
) -> Figure:
|
|
113
|
+
fig = Figure(
|
|
114
|
+
figsize=figsize,
|
|
115
|
+
facecolor=style.background_color,
|
|
116
|
+
edgecolor=style.background_color,
|
|
117
|
+
)
|
|
118
|
+
ax = Axes(fig=fig, facecolor=style.background_color)
|
|
119
|
+
self.aplot(
|
|
120
|
+
title=title,
|
|
121
|
+
style=style,
|
|
122
|
+
sort_by=sort_by,
|
|
123
|
+
ascending=ascending,
|
|
124
|
+
max_values=max_values,
|
|
125
|
+
ax=ax,
|
|
126
|
+
)
|
|
127
|
+
return fig
|
|
128
|
+
|
|
129
|
+
|
|
92
130
|
def aplot_table(
|
|
93
131
|
pd_df: pd.DataFrame,
|
|
94
132
|
cols: List[str],
|
|
@@ -98,6 +136,7 @@ def aplot_table(
|
|
|
98
136
|
sort_by: Optional[str] = None,
|
|
99
137
|
ascending: bool = False,
|
|
100
138
|
ax: Optional[Axes] = None,
|
|
139
|
+
**kwargs: Any,
|
|
101
140
|
) -> Axes:
|
|
102
141
|
"""Render a table into the provided axes.
|
|
103
142
|
|
|
@@ -140,29 +179,16 @@ def aplot_table(
|
|
|
140
179
|
>>> fig, ax = plt.subplots()
|
|
141
180
|
>>> aplot_table(df, cols=['col1', 'col2'], ax=ax)
|
|
142
181
|
"""
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
cellLoc="center",
|
|
152
|
-
colWidths=style.col_widths,
|
|
153
|
-
bbox=Bbox.from_bounds(0, -0.3, 1, 1.3),
|
|
182
|
+
return TablePlot(pd_df=pd_df, cols=cols).aplot(
|
|
183
|
+
title=title,
|
|
184
|
+
style=style,
|
|
185
|
+
sort_by=sort_by,
|
|
186
|
+
ascending=ascending,
|
|
187
|
+
max_values=max_values,
|
|
188
|
+
ax=ax,
|
|
189
|
+
**kwargs,
|
|
154
190
|
)
|
|
155
191
|
|
|
156
|
-
_format_table(table_plot, style)
|
|
157
|
-
|
|
158
|
-
ax.set_facecolor(style.background_color)
|
|
159
|
-
ax.set_axis_off()
|
|
160
|
-
ax.grid(False)
|
|
161
|
-
if title:
|
|
162
|
-
ax.set_title(title, color=style.font_color, fontsize=style.font_size * 2)
|
|
163
|
-
ax.title.set_position((0.5, 1.05))
|
|
164
|
-
return ax
|
|
165
|
-
|
|
166
192
|
|
|
167
193
|
def fplot_table(
|
|
168
194
|
pd_df: pd.DataFrame,
|
|
@@ -173,8 +199,6 @@ def fplot_table(
|
|
|
173
199
|
sort_by: Optional[str] = None,
|
|
174
200
|
ascending: bool = False,
|
|
175
201
|
figsize: Tuple[float, float] = FIG_SIZE,
|
|
176
|
-
save_path: Optional[str] = None,
|
|
177
|
-
savefig_kwargs: Optional[Dict[str, Any]] = None,
|
|
178
202
|
) -> Figure:
|
|
179
203
|
"""Return a new figure containing a formatted table.
|
|
180
204
|
|
|
@@ -215,10 +239,11 @@ def fplot_table(
|
|
|
215
239
|
>>> df = pd.DataFrame(data)
|
|
216
240
|
>>> fig = fplot_table(df, cols=['col1', 'col2'])
|
|
217
241
|
"""
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
242
|
+
return TablePlot(pd_df=pd_df, cols=cols).fplot(
|
|
243
|
+
title=title,
|
|
244
|
+
style=style,
|
|
245
|
+
sort_by=sort_by,
|
|
246
|
+
ascending=ascending,
|
|
247
|
+
max_values=max_values,
|
|
248
|
+
figsize=figsize,
|
|
249
|
+
)
|
|
@@ -8,11 +8,12 @@ import seaborn as sns
|
|
|
8
8
|
from matplotlib.axes import Axes
|
|
9
9
|
from matplotlib.figure import Figure
|
|
10
10
|
|
|
11
|
-
from .
|
|
11
|
+
from .base_plot import BasePlot
|
|
12
|
+
from .utils import _get_axis
|
|
13
|
+
from .style_template import (
|
|
12
14
|
TIMESERIE_STYLE_TEMPLATE,
|
|
13
15
|
FIG_SIZE,
|
|
14
16
|
StyleTemplate,
|
|
15
|
-
bmk_formatter,
|
|
16
17
|
format_func,
|
|
17
18
|
string_formatter,
|
|
18
19
|
validate_dataframe,
|
|
@@ -20,6 +21,11 @@ from .StyleTemplate import (
|
|
|
20
21
|
FormatterFunc,
|
|
21
22
|
)
|
|
22
23
|
|
|
24
|
+
__all__ = [
|
|
25
|
+
"TIMESERIE_STYLE_TEMPLATE",
|
|
26
|
+
"aplot_timeserie",
|
|
27
|
+
"fplot_timeserie",
|
|
28
|
+
]
|
|
23
29
|
|
|
24
30
|
# region Line
|
|
25
31
|
|
|
@@ -179,6 +185,71 @@ def _setup_timeserie_axes(
|
|
|
179
185
|
ax.grid(True)
|
|
180
186
|
|
|
181
187
|
|
|
188
|
+
class TimeSeriePlot(BasePlot):
|
|
189
|
+
"""Class for plotting time series."""
|
|
190
|
+
|
|
191
|
+
def __init__(self, pd_df: pd.DataFrame, label: str, x: str, y: str):
|
|
192
|
+
validate_dataframe(pd_df, cols=[label, x, y])
|
|
193
|
+
super().__init__(pd_df=pd_df)
|
|
194
|
+
self.label = label
|
|
195
|
+
self.x = x
|
|
196
|
+
self.y = y
|
|
197
|
+
|
|
198
|
+
def aplot(
|
|
199
|
+
self,
|
|
200
|
+
title: Optional[str] = None,
|
|
201
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
202
|
+
max_values: int = 100,
|
|
203
|
+
sort_by: Optional[str] = None,
|
|
204
|
+
ascending: bool = False,
|
|
205
|
+
std: bool = False,
|
|
206
|
+
ax: Optional[Axes] = None,
|
|
207
|
+
**kwargs: Any,
|
|
208
|
+
) -> Axes:
|
|
209
|
+
df = _prepare_timeserie_data(self._obj, self.label, self.x, self.y, sort_by)
|
|
210
|
+
format_funcs = format_func(
|
|
211
|
+
style.format_funcs, label=self.label, x=self.x, y=self.y
|
|
212
|
+
)
|
|
213
|
+
plot_ax = _get_axis(ax)
|
|
214
|
+
_plot_timeserie_lines(
|
|
215
|
+
plot_ax, df, self.label, self.x, self.y, std, style, format_funcs
|
|
216
|
+
)
|
|
217
|
+
_setup_timeserie_axes(plot_ax, self.label, self.x, self.y, style, format_funcs)
|
|
218
|
+
|
|
219
|
+
if title:
|
|
220
|
+
plot_ax.set_title(
|
|
221
|
+
title, color=style.font_color, fontsize=style.font_size + 4
|
|
222
|
+
)
|
|
223
|
+
return plot_ax
|
|
224
|
+
|
|
225
|
+
def fplot(
|
|
226
|
+
self,
|
|
227
|
+
title: Optional[str] = None,
|
|
228
|
+
style: StyleTemplate = TIMESERIE_STYLE_TEMPLATE,
|
|
229
|
+
max_values: int = 100,
|
|
230
|
+
sort_by: Optional[str] = None,
|
|
231
|
+
ascending: bool = False,
|
|
232
|
+
std: bool = False,
|
|
233
|
+
figsize: Tuple[float, float] = FIG_SIZE,
|
|
234
|
+
) -> Figure:
|
|
235
|
+
fig = Figure(
|
|
236
|
+
figsize=figsize,
|
|
237
|
+
facecolor=style.background_color,
|
|
238
|
+
edgecolor=style.background_color,
|
|
239
|
+
)
|
|
240
|
+
ax = Axes(fig=fig, facecolor=style.background_color)
|
|
241
|
+
self.aplot(
|
|
242
|
+
title=title,
|
|
243
|
+
style=style,
|
|
244
|
+
max_values=max_values,
|
|
245
|
+
sort_by=sort_by,
|
|
246
|
+
ascending=ascending,
|
|
247
|
+
std=std,
|
|
248
|
+
ax=ax,
|
|
249
|
+
)
|
|
250
|
+
return fig
|
|
251
|
+
|
|
252
|
+
|
|
182
253
|
def aplot_timeserie(
|
|
183
254
|
pd_df: pd.DataFrame,
|
|
184
255
|
label: str,
|
|
@@ -191,6 +262,7 @@ def aplot_timeserie(
|
|
|
191
262
|
ascending: bool = False,
|
|
192
263
|
std: bool = False,
|
|
193
264
|
ax: Optional[Axes] = None,
|
|
265
|
+
**kwargs: Any,
|
|
194
266
|
) -> Axes:
|
|
195
267
|
"""Plot a time series on the provided axes.
|
|
196
268
|
|
|
@@ -243,20 +315,16 @@ def aplot_timeserie(
|
|
|
243
315
|
>>> fig, ax = plt.subplots()
|
|
244
316
|
>>> aplot_timeserie(df, label='category', x='date', y='value', ax=ax)
|
|
245
317
|
"""
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if title:
|
|
258
|
-
ax.set_title(title, color=style.font_color, fontsize=style.font_size + 4)
|
|
259
|
-
return ax
|
|
318
|
+
return TimeSeriePlot(pd_df=pd_df, label=label, x=x, y=y).aplot(
|
|
319
|
+
title=title,
|
|
320
|
+
style=style,
|
|
321
|
+
max_values=max_values,
|
|
322
|
+
sort_by=sort_by,
|
|
323
|
+
ascending=ascending,
|
|
324
|
+
std=std,
|
|
325
|
+
ax=ax,
|
|
326
|
+
**kwargs,
|
|
327
|
+
)
|
|
260
328
|
|
|
261
329
|
|
|
262
330
|
def fplot_timeserie(
|
|
@@ -271,10 +339,8 @@ def fplot_timeserie(
|
|
|
271
339
|
ascending: bool = False,
|
|
272
340
|
std: bool = False,
|
|
273
341
|
figsize: Tuple[float, float] = FIG_SIZE,
|
|
274
|
-
save_path: Optional[str] = None,
|
|
275
|
-
savefig_kwargs: Optional[Dict[str, Any]] = None,
|
|
276
342
|
) -> Figure:
|
|
277
|
-
"""Return a figure
|
|
343
|
+
"""Return a new figure containing a time series plot.
|
|
278
344
|
|
|
279
345
|
Parameters
|
|
280
346
|
----------
|
|
@@ -287,19 +353,19 @@ def fplot_timeserie(
|
|
|
287
353
|
y : str
|
|
288
354
|
Column for the y-axis values.
|
|
289
355
|
title : str, optional
|
|
290
|
-
Plot title.
|
|
356
|
+
Plot title. The default is None.
|
|
291
357
|
style : StyleTemplate, optional
|
|
292
|
-
Style configuration. The default is
|
|
358
|
+
Style configuration. The default is ``TIMESERIE_STYLE_TEMPLATE``.
|
|
293
359
|
max_values : int, optional
|
|
294
360
|
Maximum number of rows to plot. The default is 100.
|
|
295
361
|
sort_by : str, optional
|
|
296
|
-
Column used to sort the data.
|
|
362
|
+
Column used to sort the data. The default is None.
|
|
297
363
|
ascending : bool, optional
|
|
298
|
-
Sort order for the data. The default is
|
|
364
|
+
Sort order for the data. The default is False.
|
|
299
365
|
std : bool, optional
|
|
300
|
-
Whether to plot rolling standard deviation. The default is
|
|
366
|
+
Whether to plot rolling standard deviation. The default is False.
|
|
301
367
|
figsize : tuple[float, float], optional
|
|
302
|
-
Size of the created figure. The default is FIG_SIZE
|
|
368
|
+
Size of the created figure. The default is ``FIG_SIZE``.
|
|
303
369
|
|
|
304
370
|
Returns
|
|
305
371
|
-------
|
|
@@ -316,32 +382,22 @@ def fplot_timeserie(
|
|
|
316
382
|
>>> import pandas as pd
|
|
317
383
|
>>> from MatplotLibAPI.Timeserie import fplot_timeserie
|
|
318
384
|
>>> data = {
|
|
319
|
-
...
|
|
320
|
-
...
|
|
321
|
-
...
|
|
385
|
+
... "date": pd.to_datetime(["2023-01-01", "2023-01-02", "2023-01-01", "2023-01-02"]),
|
|
386
|
+
... "category": ["A", "A", "B", "B"],
|
|
387
|
+
... "value": [10, 12, 15, 13],
|
|
322
388
|
... }
|
|
323
389
|
>>> df = pd.DataFrame(data)
|
|
324
|
-
>>> fig = fplot_timeserie(df, label=
|
|
390
|
+
>>> fig = fplot_timeserie(df, label="category", x="date", y="value")
|
|
325
391
|
"""
|
|
326
|
-
|
|
327
|
-
fig.patch.set_facecolor(style.background_color)
|
|
328
|
-
ax = fig.add_subplot()
|
|
329
|
-
ax = aplot_timeserie(
|
|
330
|
-
pd_df=pd_df,
|
|
331
|
-
label=label,
|
|
332
|
-
x=x,
|
|
333
|
-
y=y,
|
|
392
|
+
return TimeSeriePlot(pd_df=pd_df, label=label, x=x, y=y).fplot(
|
|
334
393
|
title=title,
|
|
335
394
|
style=style,
|
|
336
395
|
max_values=max_values,
|
|
337
|
-
std=std,
|
|
338
396
|
sort_by=sort_by,
|
|
339
397
|
ascending=ascending,
|
|
340
|
-
|
|
398
|
+
std=std,
|
|
399
|
+
figsize=figsize,
|
|
341
400
|
)
|
|
342
|
-
if save_path:
|
|
343
|
-
fig.savefig(save_path, **(savefig_kwargs or {}))
|
|
344
|
-
return fig
|
|
345
401
|
|
|
346
402
|
|
|
347
403
|
# endregion
|