direl-ts-tool-kit 0.1.0__py3-none-any.whl → 0.2.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.
- direl_ts_tool_kit/plot/__init__.py +2 -0
- direl_ts_tool_kit/plot/plot_style.py +48 -0
- direl_ts_tool_kit/plot/plot_ts.py +99 -0
- {direl_ts_tool_kit-0.1.0.dist-info → direl_ts_tool_kit-0.2.0.dist-info}/METADATA +1 -1
- direl_ts_tool_kit-0.2.0.dist-info/RECORD +9 -0
- {direl_ts_tool_kit-0.1.0.dist-info → direl_ts_tool_kit-0.2.0.dist-info}/licenses/LICENCE +0 -0
- {direl_ts_tool_kit-0.1.0.dist-info → direl_ts_tool_kit-0.2.0.dist-info}/top_level.txt +0 -0
- direl_ts_tool_kit-0.1.0.dist-info/RECORD +0 -6
- {direl_ts_tool_kit-0.1.0.dist-info → direl_ts_tool_kit-0.2.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import matplotlib.dates as mdates
|
|
3
|
+
|
|
4
|
+
plt.style.use("fast")
|
|
5
|
+
|
|
6
|
+
plt.rc("figure", autolayout=True, figsize=(12, 5))
|
|
7
|
+
|
|
8
|
+
plt.rc(
|
|
9
|
+
"axes",
|
|
10
|
+
labelweight="bold",
|
|
11
|
+
labelsize=15,
|
|
12
|
+
titleweight="bold",
|
|
13
|
+
titlesize=14,
|
|
14
|
+
titlepad=10,
|
|
15
|
+
facecolor="white",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
plt.rc("xtick", labelsize=15)
|
|
19
|
+
plt.rc("ytick", labelsize=15)
|
|
20
|
+
plt.rc("legend", fontsize=10)
|
|
21
|
+
|
|
22
|
+
plot_params = {
|
|
23
|
+
"color": "0.75",
|
|
24
|
+
"style": ".-",
|
|
25
|
+
"markeredgecolor": "0.25",
|
|
26
|
+
"markerfacecolor": "0.25",
|
|
27
|
+
"legend": False,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
paper_colors = {
|
|
32
|
+
"BLUE_LINES": "#396AB1",
|
|
33
|
+
"ORANGE_LINES": "#DA7C30",
|
|
34
|
+
"GREEN_LINES": "#3E9651",
|
|
35
|
+
"RED_LINES": "#CC2529",
|
|
36
|
+
"GRAY_LINES": "#535154",
|
|
37
|
+
"PURPLE_LINES": "#6B4C9A",
|
|
38
|
+
"MAROON_LINES": "#922428",
|
|
39
|
+
"GOLD_LINES": "#948B3D",
|
|
40
|
+
"BLUE_BARS": "#7293CB",
|
|
41
|
+
"ORANGE_BARS": "#E1974C",
|
|
42
|
+
"GREEN_BARS": "#84BA5B",
|
|
43
|
+
"RED_BARS": "#D35E60",
|
|
44
|
+
"GRAY_BARS": "#808585",
|
|
45
|
+
"PURPLE_BARS": "#90679D",
|
|
46
|
+
"MAROON_BARS": "#AB6857",
|
|
47
|
+
"GOLD_BARS": "#CCC210",
|
|
48
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from .plot_style import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def plot_time_series(
|
|
5
|
+
df1, variable, units="", color="BLUE_LINES", time_unit="Year", rot=90, method=True
|
|
6
|
+
):
|
|
7
|
+
"""
|
|
8
|
+
Plots a time series with custom styling and dual-level grid visibility.
|
|
9
|
+
|
|
10
|
+
This function automatically sets major and minor time-based locators
|
|
11
|
+
on the x-axis based on the specified time unit, and formats the y-axis
|
|
12
|
+
to use scientific notation.
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
df1 : pd.DataFrame
|
|
17
|
+
The DataFrame containing the time series data. Must have a DatetimeIndex.
|
|
18
|
+
variable : str
|
|
19
|
+
The name of the column to plot. The label is automatically formatted
|
|
20
|
+
(e.g., 'total_sales' becomes 'Total Sales').
|
|
21
|
+
units : str, optional
|
|
22
|
+
Units to display next to the variable name on the y-axis (e.g., 'USD').
|
|
23
|
+
Defaults to "".
|
|
24
|
+
color : str, optional
|
|
25
|
+
Key corresponding to the line color in the global 'paper_colors' dictionary.
|
|
26
|
+
Defaults to "BLUE_LINES".
|
|
27
|
+
time_unit : str, optional
|
|
28
|
+
The time granularity of the data to define x-axis tick locators.
|
|
29
|
+
Options include 'Year', 'Month', 'Weekday', or 'Day'. Defaults to "Year".
|
|
30
|
+
rot : int, optional
|
|
31
|
+
Rotation angle (in degrees) for the x-axis tick labels. Defaults to 90.
|
|
32
|
+
method : bool, optional
|
|
33
|
+
Used internally for label formatting logic. Defaults to True.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
matplotlib.figure.Figure
|
|
38
|
+
The generated matplotlib figure object.
|
|
39
|
+
|
|
40
|
+
Notes
|
|
41
|
+
-----
|
|
42
|
+
Major grid lines are displayed with a dashed line ('--'), and minor grid
|
|
43
|
+
lines are displayed with a dotted line (':') for detailed temporal analysis.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
fig, ax = plt.subplots()
|
|
47
|
+
ax.plot(df1.index, df1[variable], linewidth=3, color=paper_colors[color])
|
|
48
|
+
|
|
49
|
+
if "-" in variable:
|
|
50
|
+
variable = "-".join(
|
|
51
|
+
[
|
|
52
|
+
j.title() if i == 0 else j.lower()
|
|
53
|
+
for i, j in enumerate(variable.split("-"))
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
elif "_" in variable:
|
|
57
|
+
variable = " ".join(
|
|
58
|
+
[
|
|
59
|
+
j.title() if i == 0 else j.lower()
|
|
60
|
+
for i, j in enumerate(variable.split("_"))
|
|
61
|
+
]
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
variable = (
|
|
65
|
+
" ".join(
|
|
66
|
+
[
|
|
67
|
+
j.title() if i == 0 else j.lower()
|
|
68
|
+
for i, j in enumerate(variable.split())
|
|
69
|
+
]
|
|
70
|
+
)
|
|
71
|
+
if method
|
|
72
|
+
else variable
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
ax.set(xlabel=f"{time_unit}", ylabel=f"{variable} {units}")
|
|
76
|
+
ax.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
|
|
77
|
+
|
|
78
|
+
if time_unit == "Year":
|
|
79
|
+
ax.xaxis.set_major_locator(mdates.YearLocator())
|
|
80
|
+
ax.xaxis.set_minor_locator(mdates.MonthLocator())
|
|
81
|
+
|
|
82
|
+
if time_unit == "Month":
|
|
83
|
+
ax.xaxis.set_major_locator(mdates.MonthLocator())
|
|
84
|
+
ax.xaxis.set_minor_locator(mdates.WeekdayLocator())
|
|
85
|
+
|
|
86
|
+
if time_unit == "Weekday":
|
|
87
|
+
ax.xaxis.set_major_locator(mdates.WeekdayLocator())
|
|
88
|
+
ax.xaxis.set_minor_locator(mdates.DayLocator())
|
|
89
|
+
|
|
90
|
+
if time_unit == "Day":
|
|
91
|
+
ax.xaxis.set_major_locator(mdates.DayLocator())
|
|
92
|
+
ax.xaxis.set_minor_locator(mdates.HourLocator())
|
|
93
|
+
|
|
94
|
+
ax.tick_params(axis="x", rotation=rot)
|
|
95
|
+
ax.grid(which="both")
|
|
96
|
+
ax.grid(which="minor", alpha=0.6, linestyle=":")
|
|
97
|
+
ax.grid(which="major", alpha=0.8, linestyle="--")
|
|
98
|
+
|
|
99
|
+
return fig
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
direl_ts_tool_kit/__init__.py,sha256=E7sCCqFQm9KG6fdpVX7vdVK1QIMPlygEyS_6hqpN1Bw,59
|
|
2
|
+
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
|
+
direl_ts_tool_kit/plot/plot_style.py,sha256=vhzcDa3LzgkHuy-GnliofGZ8TDntkm3_1C5kgl2Gx3E,1010
|
|
4
|
+
direl_ts_tool_kit/plot/plot_ts.py,sha256=MopIqV4uBaJ9wCdjOhuKaiW5McmXejoA2Co46DzAiIQ,3334
|
|
5
|
+
direl_ts_tool_kit-0.2.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
direl_ts_tool_kit-0.2.0.dist-info/METADATA,sha256=D0pY1HYO1EClxT0wlr9i1urdHWNjYoIpY_KRuJuEu2E,922
|
|
7
|
+
direl_ts_tool_kit-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
direl_ts_tool_kit-0.2.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
9
|
+
direl_ts_tool_kit-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
direl_ts_tool_kit/__init__.py,sha256=E7sCCqFQm9KG6fdpVX7vdVK1QIMPlygEyS_6hqpN1Bw,59
|
|
2
|
-
direl_ts_tool_kit-0.1.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
direl_ts_tool_kit-0.1.0.dist-info/METADATA,sha256=T5LKz-k7EKvd1Le2R9-wgRFiq0x67e9F6vKGnF4G0Fw,922
|
|
4
|
-
direl_ts_tool_kit-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
-
direl_ts_tool_kit-0.1.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
6
|
-
direl_ts_tool_kit-0.1.0.dist-info/RECORD,,
|
|
File without changes
|