Skip to content

Commit 5b8cabd

Browse files
committed
Plot fixed
1 parent abe8a30 commit 5b8cabd

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

‎week7/util.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import plotly.graph_objects as go
66
from itertools import accumulate
77
import math
8-
from tqdm.notebook import tqdm
9-
import plotly.io as pio
8+
from tqdm.auto import tqdm
9+
from IPython.display import clear_output
1010

11-
pio.renderers.default = "colab"
1211

1312
GREEN = "\033[92m"
1413
YELLOW = "\033[93m"
@@ -91,8 +90,8 @@ def chart(self, title):
9190
color_discrete_map={"green": "green", "orange": "orange", "red": "red"},
9291
title=title,
9392
labels={"truth": "Actual Price", "guess": "Predicted Price"},
94-
width=1000,
95-
height=800,
93+
width=800,
94+
height=600,
9695
)
9796

9897
# Assign customdata per trace (one color/category = one trace)
@@ -139,6 +138,11 @@ def error_trend_chart(self):
139138
upper = [m + c for m, c in zip(running_means, ci)]
140139
lower = [m - c for m, c in zip(running_means, ci)]
141140

141+
# Title with final stats
142+
final_mean = running_means[-1]
143+
final_ci = ci[-1]
144+
title = f"{self.title} Error: {final_mean:,.2f} ± {final_ci:,.2f}"
145+
142146
# Plot
143147
fig = go.Figure()
144148

@@ -177,17 +181,12 @@ def error_trend_chart(self):
177181
)
178182
)
179183

180-
# Title with final stats
181-
final_mean = running_means[-1]
182-
final_ci = ci[-1]
183-
title = f"{self.title} Error: ${final_mean:,.2f} ± ${final_ci:,.2f}"
184-
185184
fig.update_layout(
186185
title=title,
187186
xaxis_title="Number of Datapoints",
188-
yaxis_title="Average Absolute Error ($)",
189-
width=1000,
190-
height=360,
187+
yaxis_title="Error ($)",
188+
width=800,
189+
height=300,
191190
template="plotly_white",
192191
showlegend=False,
193192
)
@@ -203,14 +202,15 @@ def report(self):
203202
self.chart(title)
204203

205204
def run(self):
206-
for i in tqdm(range(self.size), total=self.size):
205+
for i in tqdm(range(self.size)):
207206
title, guess, truth, error, color = self.run_datapoint(i)
208207
self.titles.append(title)
209208
self.guesses.append(guess)
210209
self.truths.append(truth)
211210
self.errors.append(error)
212211
self.colors.append(color)
213212
print(f"{COLOR_MAP[color]}${error:.0f} ", end="")
213+
clear_output(wait=True)
214214
self.report()
215215

216216

0 commit comments

Comments
 (0)