Skip to content

Commit 0f55c85

Browse files
committed
Gave user the option to not visualise the variance with the 'visualize_variance' argument
1 parent c5c86b5 commit 0f55c85

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

truelearn/utils/visualisations/_bar_plotter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ def __init__(
4141
ylabel: The default y label of the visualization
4242
"""
4343
super().__init__(title, xlabel, ylabel)
44-
44+
45+
# pylint: disable=too-many-arguments
4546
def plot(
4647
self,
4748
content: Knowledge,
4849
topics: Optional[Iterable[str]] = None,
4950
top_n: Optional[int] = None,
5051
history: bool = False,
52+
visualize_variance: bool = True,
5153
) -> Self:
5254
"""Plot the graph based on the given data.
5355
@@ -68,6 +70,8 @@ def plot(
6870
Whether to utilize history information in the visualisation.
6971
If this is set to True, an attribute called history must be
7072
present in all knowledge components.
73+
visualize_variance:
74+
Whether to visualise variance.
7175
"""
7276
content_dict, _ = self._standardise_data(content, history, topics)
7377
content_dict = content_dict[:top_n]
@@ -106,7 +110,7 @@ def plot(
106110
"color": "black",
107111
"thickness": 4,
108112
"width": 3,
109-
"visible": True,
113+
"visible": visualize_variance,
110114
},
111115
customdata=np.transpose(
112116
[variances, number_of_videos, last_video_watched] # type: ignore

truelearn/utils/visualisations/_dot_plotter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ def __init__(
4242
"""
4343
super().__init__(title, xlabel, ylabel)
4444

45+
# pylint: disable=too-many-arguments
4546
def plot(
4647
self,
4748
content: Knowledge,
4849
topics: Optional[Iterable[str]] = None,
4950
top_n: Optional[int] = None,
5051
history: bool = False,
52+
visualize_variance: bool = True,
5153
) -> Self:
5254
"""Plot the graph based on the given data.
5355
@@ -68,6 +70,8 @@ def plot(
6870
Whether to utilize history information in the visualisation.
6971
If this is set to True, an attribute called history must be
7072
present in all knowledge components.
73+
visualize_variance:
74+
Whether to visualise variance.
7175
"""
7276
content_dict, _ = self._standardise_data(content, history, topics)
7377
content_dict = content_dict[:top_n]
@@ -106,7 +110,7 @@ def plot(
106110
"color": "black",
107111
"thickness": 4,
108112
"width": 3,
109-
"visible": True,
113+
"visible": visualize_variance,
110114
},
111115
customdata=np.transpose(
112116
[variances, number_of_videos, last_video_watched] # type: ignore

truelearn/utils/visualisations/_line_plotter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def plot(
8282
content: Union[List[Knowledge], Knowledge],
8383
topics: Optional[Iterable[str]] = None,
8484
top_n: Optional[int] = None,
85-
variance: bool = False,
85+
visualize_variance: bool = False,
8686
) -> Self:
8787
"""Plot the graph based on the given data.
8888
@@ -100,7 +100,7 @@ def plot(
100100
top_n:
101101
The number of topics to visualise. E.g. if top_n is 5, then the
102102
top 5 topics ranked by mean will be visualised.
103-
variance:
103+
visualize_variance:
104104
Whether to visualise variance.
105105
"""
106106
if isinstance(content, list):
@@ -111,7 +111,7 @@ def plot(
111111
if not content_dict:
112112
return self
113113

114-
traces = [self._trace(tr_data, variance) for tr_data in content_dict]
114+
traces = [self._trace(tr_data, visualize_variance) for tr_data in content_dict]
115115

116116
self.figure.add_traces(traces)
117117

@@ -152,7 +152,7 @@ def _content_for_multiple(
152152
def _trace(
153153
self,
154154
tr_data: Tuple[Iterable[float], Iterable[float], str, Iterable[float]],
155-
visualise_variance: bool,
155+
visualize_variance: bool,
156156
) -> go.Scatter:
157157
"""Return the Scatter object representing a single line.
158158
@@ -161,7 +161,7 @@ def _trace(
161161
The data used to plot the line. A tuple containing the mean
162162
and variance of each point, the name of the line (the topic or
163163
the learner it represents) and the time when the learning event happens.
164-
visualise_variance:
164+
visualize_variance:
165165
Whether to make the error bars at each point visible.
166166
"""
167167
means, variances, name, timestamps = tr_data
@@ -175,7 +175,7 @@ def _trace(
175175
line={"width": 2},
176176
error_y={
177177
"array": variances,
178-
"visible": visualise_variance,
178+
"visible": visualize_variance,
179179
},
180180
)
181181

truelearn/utils/visualisations/_radar_plotter.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def plot(
3333
content: Knowledge,
3434
topics: Optional[Iterable[str]] = None,
3535
top_n: Optional[int] = None,
36+
visualize_variance: bool = True,
3637
) -> Self:
3738
"""Plot the graph based on the given data.
3839
@@ -49,6 +50,8 @@ def plot(
4950
top_n:
5051
The number of topics to visualise. E.g. if top_n is 5, then the
5152
top 5 topics ranked by mean will be visualised.
53+
visualize_variance:
54+
Whether to visualise variance.
5255
"""
5356
content_dict, _ = self._standardise_data(content, False, topics)
5457
content_dict = content_dict[:top_n]
@@ -65,13 +68,15 @@ def plot(
6568
variances.append(variances[0])
6669
titles.append(titles[0])
6770

68-
self.figure.add_traces(
69-
[
70-
self._trace(means, titles, "Means"),
71-
self._trace(variances, titles, "Variances"),
72-
],
71+
self.figure.add_trace(
72+
self._trace(means, titles, "Means"),
7373
)
7474

75+
if visualize_variance:
76+
self.figure.add_trace(
77+
self._trace(variances, titles, "Variances")
78+
)
79+
7580
self.figure.update_layout(
7681
polar={
7782
"radialaxis": {

0 commit comments

Comments
 (0)