-
Notifications
You must be signed in to change notification settings - Fork 0
/
JIF_covid_plot.py
148 lines (136 loc) · 4.25 KB
/
JIF_covid_plot.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# For the annual report, need all years at present (may limit to same as fellows/inf/aff in future)
import pandas as pd
import os
import plotly.graph_objects as go
from colour_science_2023 import (
SCILIFE_COLOURS,
)
# ScilifeLab/KAW COVID papers
from JIF_covid_data_prep import JIF_sub_group_cov
def JIF_graph_func(input, name):
JIFcounts = input
# split down dataframes to enable stacking
UnknownJIF = JIFcounts[(JIFcounts["JIFcat"] == "JIF unknown")]
Undersix = JIFcounts[(JIFcounts["JIFcat"] == "JIF <6")]
sixtonine = JIFcounts[(JIFcounts["JIFcat"] == "JIF 6-9")]
ninetotwentyfive = JIFcounts[(JIFcounts["JIFcat"] == "JIF 9-25")]
overtwentyfive = JIFcounts[(JIFcounts["JIFcat"] == "JIF >25")]
# Make stacked bar chart
fig = go.Figure(
data=[
go.Bar(
name="JIF unknown",
x=UnknownJIF.Year,
y=UnknownJIF.Count,
marker=dict(
color=SCILIFE_COLOURS[17], line=dict(color="#000000", width=1)
),
),
go.Bar(
name="JIF < 6",
x=Undersix.Year,
y=Undersix.Count,
marker=dict(
color=SCILIFE_COLOURS[12], line=dict(color="#000000", width=1)
),
),
go.Bar(
name="JIF 6 - 9",
x=sixtonine.Year,
y=sixtonine.Count,
marker=dict(
color=SCILIFE_COLOURS[4], line=dict(color="#000000", width=1)
),
),
go.Bar(
name="JIF 9 - 25",
x=ninetotwentyfive.Year,
y=ninetotwentyfive.Count,
marker=dict(
color=SCILIFE_COLOURS[0], line=dict(color="#000000", width=1)
),
),
go.Bar(
name="JIF > 25",
x=overtwentyfive.Year,
y=overtwentyfive.Count,
marker=dict(
color=SCILIFE_COLOURS[8], line=dict(color="#000000", width=1)
),
),
]
)
fig.update_layout(
barmode="stack",
plot_bgcolor="white",
autosize=False,
font=dict(size=30), # 58 for fellows
margin=dict(r=125, t=0, b=0, l=0),
width=900,
height=600,
showlegend=False,
)
# List years to use in x-axis
Years = JIFcounts["Year"].unique().astype(str)
Years_int = JIFcounts["Year"].unique()
# modify x-axis
fig.update_xaxes(
title=" ",
showgrid=True,
linecolor="black",
# add more years as needed
ticktext=[
"<b> 2020 </b>", # 2017
"<b> 2021 </b>", # 2017
"<b> 2022 </b>", # 2017
"<b> 2023 </b>", # 2017
],
tickvals=[
Years[0],
Years[1],
Years[2],
Years[3],
],
)
Year_one = JIFcounts[(JIFcounts["Year"] == Years_int[0])]
Year_two = JIFcounts[(JIFcounts["Year"] == Years_int[1])]
Year_three = JIFcounts[(JIFcounts["Year"] == Years_int[2])]
Year_four = JIFcounts[(JIFcounts["Year"] == Years_int[3])]
highest_y_value = max(
Year_one["Count"].sum(),
Year_two["Count"].sum(),
Year_three["Count"].sum(),
Year_four["Count"].sum(),
)
if highest_y_value < 10:
yaxis_tick = 1
if highest_y_value > 10:
yaxis_tick = 2
if highest_y_value > 20:
yaxis_tick = 5
if highest_y_value > 50:
yaxis_tick = 10
if highest_y_value > 100:
yaxis_tick = 20
if highest_y_value > 150:
yaxis_tick = 40
if highest_y_value > 500:
yaxis_tick = 100
if highest_y_value > 1000:
yaxis_tick = 100
# modify y-axis
fig.update_yaxes(
title=" ",
showgrid=True,
gridcolor="lightgrey",
linecolor="black",
dtick=yaxis_tick,
range=[0, int(highest_y_value * 1.1)],
)
if not os.path.isdir("Plots/"):
os.mkdir("Plots/")
# fig.show()
fig.write_image("Plots/{}_JIF.png".format(name))
fig.write_image("Plots/{}_JIF.svg".format(name))
# make plots by applying function
JIF_graph_func(JIF_sub_group_cov, "covid")