我之前为课程提交的一个项目按预期工作。我回去再次运行代码,现在收到一条之前没有出现过的 python 回溯错误消息: 'matplotlib.pyplot' has no attribute 'autofmt_xdate'
我加载了气象站数据文件并运行了之前有效的所有代码。以下是可视化图的代码:
plt.figure()
plt.plot(minmaxdf.loc[:,'Month-Day'], minmaxdf.loc[:,'min_tmps'] ,'-', c = 'cyan', linewidth=0.5, label = '10yr record lows')
plt.plot(minmaxdf.loc[:,'Month-Day'], minmaxdf.loc[:,'max_tmps'] , '-', c = 'orange', linewidth=0.5, label = '10yr record highs')
plt.gca().fill_between(range(len(minmaxdf.loc[:,'min_tmps'])), minmaxdf['min_tmps'], minmaxdf['max_tmps'], facecolor = (0.5, 0.5, 0.5), alpha = 0.5)
plt.scatter(minbreach15.loc[:,'Month-Day'], minbreach15.loc[:,'min_tmps_breach15'], s = 10, c = 'blue', label = 'Record low broken - 2015')
plt.scatter(maxbreach15.loc[:,'Month-Day'], maxbreach15.loc[:,'max_tmps_breach15'], s = 10, c = 'red', label = 'Record high broken - 2015')
plt.xlabel('Month')
plt.ylabel('Temperature (Tenths of …Run Code Online (Sandbox Code Playgroud) 我正在使用 test.testEqual() 在 Runestone 中开展一个项目。我使用 Anaconda/Spyder 控制台并将代码翻译回 Runestone。Python 似乎不支持 test.testEqual 所以我尝试在 unittest 框架下使用 TestCase.assertEqual(first,second, msg) 方法。我的代码抛出错误消息:TypeError: assertEqual() missing 1 required positional argument: 'second'
但正如我在下面的代码中所示,我在调用中包含了两个参数。我是单元测试的新手,所以不知道去哪里解决这个问题?
从 test.testEqual() 切换到 TestCase.assertEqual(first,second,msg)
from unittest import TestCase
def distance(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
dsquared = dx**2 + dy**2
result = dsquared**0.5
return result
TestCase.assertEqual(distance(1,2, 1,2),0,msg='Equal')
TestCase.assertEqual(distance(1,2, 4,6), 5, msg='Equal')
TestCase.assertEqual(distance(0,0, 1,1), 2**0.5, msg='Equal')
Run Code Online (Sandbox Code Playgroud)
我们希望这三个测试用例根据它们在 Runestone 控制台中的执行情况通过。