-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathplot_theme.py
More file actions
50 lines (42 loc) · 1.42 KB
/
Copy pathplot_theme.py
File metadata and controls
50 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations
from matplotlib import dates as mdates
from matplotlib.axes import Axes
FIG_BG = "#0b0d12"
AX_BG = "#11151c"
GRID = "#283241"
TEXT = "#e5e7eb"
SUBTEXT = "#9ca3af"
WHITE_LINE = "#f5f5f7"
BLUE_LINE = "#3b82f6"
GREEN_LINE = "#34C759"
RED_LINE = "#FF453A"
BASELINE = "#6b7280"
REGIME_COLORS = {
"favorable": "#14532d",
"selective": "#854d0e",
"caution": "#9a3412",
"risk_off": "#7f1d1d",
}
def style_dark_axis(ax: Axes) -> None:
ax.set_facecolor(AX_BG)
ax.grid(color=GRID, alpha=0.35, linewidth=0.8)
ax.tick_params(colors=SUBTEXT, labelsize=10)
for spine in ax.spines.values():
spine.set_color("#1f2937")
ax.yaxis.label.set_color(TEXT)
ax.xaxis.label.set_color(TEXT)
ax.title.set_color(TEXT)
def style_date_axis(ax: Axes, span_days: int | None = None) -> None:
if span_days is not None and span_days >= 150:
locator = mdates.MonthLocator(interval=2)
formatter = mdates.DateFormatter("%b")
elif span_days is not None and span_days >= 60:
locator = mdates.MonthLocator(interval=1)
formatter = mdates.DateFormatter("%b")
else:
locator = mdates.AutoDateLocator(minticks=4, maxticks=7)
formatter = mdates.ConciseDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.tick_params(axis="x", rotation=0)
ax.xaxis.get_offset_text().set_color(SUBTEXT)