-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsingle_year_calplot.py
77 lines (68 loc) · 1.95 KB
/
single_year_calplot.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from typing import List, Optional, Union
from pandas.core.frame import DataFrame
from plotly import graph_objects as go
from plotly_calplot.date_extractors import get_date_coordinates, get_month_names
from plotly_calplot.layout_formatter import (
create_month_lines,
decide_layout,
update_plot_with_current_layout,
)
from plotly_calplot.raw_heatmap import create_heatmap_without_formatting
def year_calplot(
data: DataFrame,
x: str,
y: str,
fig: go.Figure,
row: int,
year: int,
name: str = "y",
dark_theme: bool = False,
month_lines_width: int = 1,
month_lines_color: str = "#9e9e9e",
gap: int = 1,
colorscale: str = "greens",
title: str = "",
month_lines: bool = True,
total_height: Union[int, None] = None,
text: Optional[List[str]] = None,
text_name: Optional[str] = None,
years_as_columns: bool = False,
start_month: int = 1,
end_month: int = 12,
show_empty_months = True,
) -> go.Figure:
"""
Each year is subplotted separately and added to the main plot
"""
month_names = get_month_names(data, x, start_month, end_month, show_empty_months)
month_positions, weekdays_in_year, weeknumber_of_dates = get_date_coordinates(
data, x
)
# the calendar is actually a heatmap :)
cplt = create_heatmap_without_formatting(
data,
x,
y,
weeknumber_of_dates,
weekdays_in_year,
gap,
year,
colorscale,
name,
text=text,
text_name=text_name,
)
if month_lines:
cplt = create_month_lines(
cplt,
month_lines_color,
month_lines_width,
data[x],
weekdays_in_year,
weeknumber_of_dates,
)
layout = decide_layout(dark_theme, title, month_names, month_positions)
fig = update_plot_with_current_layout(
fig, cplt, row, layout, total_height, years_as_columns
)
return fig