【发布时间】:2012-03-26 23:15:24
【问题描述】:
我在尝试使用带有 matplottlib 的 plot() 绘制图形时遇到问题。
这是对异常进行编码的代码的 sn-p,以及异常堆栈跟踪和错误消息:
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迭代数据时调用堆栈向下 - 有人可以解释一下吗?
【问题讨论】:
-
我假设
top是Axis。在第 801 行调用其绘图成员之前,top做了什么?
标签: python matplotlib