Traceback (most recent call last):
File “/home/runner/boilerplate-sea-level-predictor-1/test_module.py”, line 34, in test_plot_lines
self.assertEqual(actual, expected, “Expected different line for first line of best fit.”)
AssertionError: Lists differ: [0.0, 0.220472441, -0.440944881, -0.232283[1677 chars]4951] != [-0.5421240249263661, -0.4790794409142336,[3256 chars]2443]
First differing element 0:
0.0
-0.5421240249263661
Second list contains 36 additional elements.
First extra element 134:
7.905850232699706
Diff is 5939 characters long. Set self.maxDiff to None to see it. : Expected different line for first line of best fit.
thnks for the response
here’s the code:
‘’’
def draw_plot():
# Read data from file
df = pd.read_csv(“epa-sea-level.csv”)
#float_precision=‘legacy’
# Create scatter plot
plt.scatter(df.Year, df[“CSIRO Adjusted Sea Level”])
plt.xlabel(‘Year’)
plt.ylabel(‘CSIRO Adjusted Sea Level’)
# Create first line of best fit
year1 = list(range(1880, 2050))
year1 = pd.Series(year1)
year2 = list(range(2000, 2050))
year2 = pd.Series(year2)
res = linregress(df.Year, df["CSIRO Adjusted Sea Level"])
df2 = df[df.Year>= 2000]
res2 = linregress(df2.Year, df2["CSIRO Adjusted Sea Level"])
plt.figure(figsize=(10,5))
plt.plot(df.Year, df["CSIRO Adjusted Sea Level"], 'o', markersize = 5.2, label='original data')
plt.plot(year1, res.intercept + res.slope*year1, 'r', linewidth=2.5, label='fitted line 1')
# Create second line of best fit
plt.plot(year2, res2.intercept + res2.slope*year2, 'r', linewidth=2.5, label='fitted line 2', color='green')
plt.legend()
# Add labels and title
plt.xlabel('Year')
plt.ylabel('Sea Level (inches)')
plt.title('Rise in Sea Level')
# Save plot and return data for testing (DO NOT MODIFY)
plt.savefig('sea_level_plot.png')
return plt.gca()
In case you are still stuck on this…
From looking at your code, it seems that you plot the actual data twice, once as an actual scatter plot (plt.scatter) and one time as a line plot (plt.plot) - this one is not needed. The test expects one scatter plot and two line plots (from the fits), and any additional lines can result in a test failure.
The next thing you’ll most likely run into is some test failure connected to “shape”. Look at your year1 and year2 ranges and check whether they actually include the year 2050…!
Good luck