1

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)

Output:

[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?

1
  • 1
    I assume top is an Axis. What has been done to top before calling its plot member in line 801?
    – Kyss Tao
    Mar 9, 2012 at 14:22

1 Answer 1

0

The output of 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.

1
  • Sorry - don't know how I misread that! I'll update the answer.
    – aquavitae
    Mar 9, 2012 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.