-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharts.py
57 lines (49 loc) · 1.49 KB
/
charts.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
import plotly.express as px
import plotly.graph_objects as go
from plotly.express.colors import sample_colorscale
def create_benefit_chart(df, benefit, spending):
subset = df[
(df.Type == ("Spending" if spending else "Caseloads"))
& (df["Benefit"] == benefit)
]
blues = sample_colorscale(
px.colors.sequential.Blues, df["Forecast year"].unique().size
)
fig = px.line(
subset,
x="Year",
y="Value",
color="Forecast year",
color_discrete_sequence=blues,
).update_layout(
height=600,
title=f"Benefit {'spending' if spending else 'caseload'} forecast for {benefit}",
width=800,
yaxis_range=[0, subset.Value.max()],
yaxis_tickprefix="£" if spending else "",
yaxis_title="Spending" if spending else "Caseload",
xaxis_title="Financial year",
)
# Make all lines dotted
for i, trace in enumerate(fig.data):
trace.line.dash = "dot"
# Add a solid line with the actual data
outturns = df[
(df.Type == ("Spending" if spending else "Caseloads"))
& (~df.Forecast)
& (df["Benefit"] == benefit)
& (df["Forecast year"] == 2024)
]
fig.add_trace(
go.Scatter(
x=outturns.Year,
y=outturns.Value,
mode="lines",
name="Outturn",
line=dict(color="black", width=3),
)
)
fig.update_layout(
xaxis_range=[2017, 2030],
)
return fig