5

I created a very simple scatter plot using pylab.

pylab.scatter(engineSize, fuelMile)
pylab.show()

The rest of the program isn't worth posting, because it's that line that's giving me the problem. When I change "scatter" to "plot" it graphs the data, but each point is part of a line and that makes the whole things a scribbly mess. I just want points, not a line, but I get this huge error message that ends with:

  File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line 1643, in amin
    return amin(axis, out)
TypeError: cannot perform reduce with flexible type
user212562
  • 195
  • 1
  • 2
  • 6
  • What values are engineSize and fuelMile storing? I think it's failing trying to convert one of those to 1-dimension. – Mark Nov 17 '09 at 03:42
  • Knowing the type of engineSize and fuelMile would be very helpful. Please consider posting some more of your code. Are they lists or numpy arrays? What type are the elements of these iterables? – Paul Nov 17 '09 at 03:44
  • 1
    also, as an aside, you can "turn off" the lines in plot() by setting linetype='' (or possibly linetype=None) as a keyword arg in plot() – Paul Nov 17 '09 at 03:48

2 Answers2

9

I bet engineSize, fuelMile are stings, try printing them, if that is the case, you have to convert them to float before passing them as arguments to scatter

floatval = float(strval)
guest
  • 121
  • 1
  • 6
2

Okay, so since this works, something must be wrong with your inputs. Clearly you need to post more, unless this "answer" solves your problem:

>>> import pylab
>>> pylab.scatter([500, 550, 700, 1100], [5.5, 6.5, 3.1, 9.7])
<matplotlib.collections.RegularPolyCollection object at 0x036F5610>
>>> pylab.show()
(graphing-type stuff ensues)
Peter Hansen
  • 21,046
  • 5
  • 50
  • 72