I am trying to plot a histogram and a scatter plot for a particular column in a given csv file. I am new to programming and I got this code from a friend, and it apparently works but somehow I am getting this error. the code is:
import csv
import numpy as np
import matplotlib.pyplot as plt
f = open('Data for question 13.csv')
data = csv.reader(f)
Area = []; MajorAxisLength = []; MinorAxisLength = []; Perimeter = []
MinIntensity = []; MeanIntensity = []; MaxIntensity = []
header = [Area, MajorAxisLength, MinorAxisLength,Perimeter,MinIntensity,MeanIntensity,MaxIntensity]
for row in data:
i = 1
for name in header:
name.append(row[i])
i = i + 1
plt.figure()
plt.hist(Area, bins=50) # error follows after this
Error:
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
plt.hist(Area, bins=50, alpha=0.5)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 2827, in hist
stacked=stacked, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 8312, in hist
xmin = min(xmin, xi.min())
File "/Library/Python/2.7/site-packages/numpy-1.9.0-py2.7-macosx-10.9-intel.egg/numpy/core/_methods.py", line 29, in _amin
return umr_minimum(a, axis, None, out, keepdims)
TypeError: cannot perform reduce with flexible type
I am unable to get rid of this error. The answer should be simple but since I am new I have no idea how to deal with it.