error de matplotlib plot (): TypeError: el objeto 'NoneType' no es iterable

I am enconterring a problem when trying to plot graphs using plot() with matplottlib.

Here is a snippet of the code that codes the exception, along with the exception stacktrace and error messages:

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)

Salida:

[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

I don't understand the internal workings of matplotlib - BUT as can be seen from the output data passed to the plot() function, there are no None types, so I don't understand why a NoneType is being encountered durther down the call stack when the data is being iterated over - can someone please explain?

preguntado el 09 de marzo de 12 a las 13:03

Asumo top es un Axis. What has been done to top before calling its plot member in line 801? -

1 Respuestas

La salida de xlocator.view_limits(x0, x1) is None, so it can't iterate to expand the output to x0, x1. I don't know why this is though. I notice that the error happens in a unit_test function, presumably matlibplot's unit tests. If that is raising an error, it looks like one of matlibplot's unit tests are failing, so perhaps you should report it.

respondido 09 mar '12, 14:03

Sorry - don't know how I misread that! I'll update the answer. - aquavitae

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.