-
Notifications
You must be signed in to change notification settings - Fork 6
/
histogram.py
87 lines (75 loc) · 2.57 KB
/
histogram.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
# Function to produce a histogram that shows the distribution of the scores
# from the student's grade level for the current week
# Plots a vertical line of the students most recent score for comparison
# Imports
import plotly.express as px
def histogram(grade_list, student_info):
"""
Plotly histogram of all of the submission scores for the student's grade
for the current week
Plots a vertical line for the student's most recent score so they can see
how it compares to the rest of the grade
Input: List of the current week's scores for the specific grade level
Student information in a list in this order:
[grade_number, student_name, student_score]
Output: Plotly JSON that can be passed to the web to display on the
parent dashboard
"""
# Dynamic variables to use for labels on the plot
grade_number, student_name, student_score = student_info
# Plot
fig = px.histogram(
x=grade_list, nbins=20, color_discrete_sequence=["#EB7E5B"]
)
fig.update_layout(
title={
"text": f"Distribution of This Week's Grade {grade_number} Stories",
"y": 0.95,
"x": 0.5,
"font": {"size": 25, "family": "PT Sans Narrow"},
},
shapes=[
dict(
type="line",
yref="paper",
y0=0,
y1=1,
xref="x",
x0=student_score,
x1=student_score,
)
],
annotations=[
dict(
x=student_score,
y=0.5,
xref="x",
yref="paper",
text=f"{student_name}'s submission",
arrowhead=5,
ax=200,
ay=-100,
showarrow=True,
font=dict(family="PT Sans Narrow", size=16, color="black"),
align="center",
arrowsize=1,
arrowwidth=2,
arrowcolor="#636363",
bordercolor="#c7c7c7",
borderwidth=2,
borderpad=4,
bgcolor="#B5D33D",
opacity=0.8,
),
],
plot_bgcolor="#6CEAE6",
)
fig.update_traces(hoverinfo="none", hovertemplate=None)
fig.update_xaxes(
title_text="Squad Score",
showticklabels=False,
title_font={"size": 20, "family": "PT Sans Narrow"},
)
fig.update_yaxes(title_text="", showticklabels=False, showgrid=False)
# Return as json for web
return fig.to_json()