Reputation: 79
I'm currently reading "Machine Learning in Action". In the chapter 8 of Regression, p.158 , there are few codes to plot original data point and a fitted line together.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(xMat[:,1].flatten().A[0] , yMat.T[:, 0].flatten().A[0])
xCopy = xMat.copy()
xCopy.sort(0)
yHat = xCopy*ws
ax.plot(xCopy[:,1], yHat)
plt.show()
xCopy and yHat are both matrix object defined by numpy.
When I use Python 3.2, running this code throws out error:
Traceback (most recent call last):
File "F:\ML\AC\Regression.py", line 44, in <module>
ax.plot(xCopy[:,1], yHat)
File "C:\Python32\lib\site-packages\matplotlib\axes.py", line 3998, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python32\lib\site-packages\matplotlib\axes.py", line 332, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python32\lib\site-packages\matplotlib\axes.py", line 291, in _plot_args
linestyle, marker, color = _process_plot_format(tup[-1])
File "C:\Python32\lib\site-packages\matplotlib\axes.py", line 99, in _process_plot_format
if fmt.find('--')>=0:
AttributeError: 'matrix' object has no attribute 'find'
But using Python 2.7, the exact same code clip works fine. Is there something difference between numpy for 2.7 and 3.2, or the matplotlib library has changed syntex from 2.7 to Python 3?
Upvotes: 2
Views: 765
Reputation: 20373
Python 3 support for matplotlib is very new, so you may experience a few bugs - and this is one of them.
As you've realised, numpy and matplotlib support for python 2.X is good, so I would stick with that if you don't want to encounter more hidden 'features'.
Upvotes: 2