尝试使用带有matplottlib的plot()绘制图形时,我会遇到一个问题。
以下是代码异常的代码片段,以及异常堆栈跟踪和错误消息:
def line_graph(p_collection, filename, *args, **kwargs):
def plot(top):
temp = [p.foo_bar for p in p_collection]
print temp
top.plot(temp, '-', label="foobar") # <- This is line 801
multi_graph(p_collection, filename, plot, *args, **kwargs)
输出:
[276.25, 274.0, 257.0, 261.0, 259.75, 256.5, 261.0, 263.75, 257.5, 260.0, 251.0, 247.5, 246.0, 243.0, 243.75, 247.0, 244.0, 246.75, 251.0, 247.75, 245.75, 241.0, 251.0, 258.0, 258.75, 257.0, 262.0, 263.0, 256.0, 260.0, 261.0, 267.0, 264.25, 261.0, 268.5, 266.0, 268.25, 268.0, 271.0, 263.5, 259.0, 262.5, 265.5, 260.0, 261.5, 258.75, 258.25, 258.5, 255.0, 255.25, 251.75, 250.25, 256.5, 248.75, 249.5, 248.25, 246.0, 248.0, 248.5, 251.0, 254.5, 249.5, 248.5, 251.0, 253.0, 258.0, 259.0, 260.0, 262.0, 269.5, 259.25, 258.0, 250.5, 250.5, 250.5, 258.25, 255.5, 247.25, 248.0, 243.0, 247.5, 248.0, 251.25, 256.0, 250.0, 245.0, 241.5, 240.25, 247.5, 247.5, 246.0, 247.0, 250.0, 243.5, 235.5, 241.5, 249.5, 243.0, 243.5, 245.25]
Traceback (most recent call last):
File "plotfuncs.py", line 1080, in <module>
unit_test()
File "plotfuncs.py", line 1072, in unit_test
left_view=(0, 40),
File "plotfuncs.py", line 802, in line_graph
multi_graph(phist, filename, plot, *args, **kwargs)
File "plotfuncs.py", line 594, in multi_graph
plot(top)
File "plotfuncs.py", line 801, in plot
top.plot(temp, '-', label="foobar")
File "/usr/local/lib/python2.6/dist-packages/matplotlib/axes.py", line 3853, in plot
self.autoscale_view(scalex=scalex, scaley=scaley)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/axes.py", line 1842, in autoscale_view
x0, x1 = xlocator.view_limits(x0, x1)
TypeError: 'NoneType' object is not iterable
我不明白matplotlib的内部工作原理 - 从输出数据传递到plot()函数可以看出,没有None类型,所以我不明白为什么会遇到NoneType当数据被迭代时调用堆栈 - 有人可以解释一下吗?
答案 0 :(得分:0)
xlocator.view_limits(x0, x1)
的输出为None,因此无法迭代将输出扩展为x0, x1
。我不知道为什么会这样。我注意到错误发生在unit_test函数中,可能是matlibplot的单元测试。如果这引发了错误,看起来matlibplot的单元测试之一就失败了,所以也许你应该报告它。