mstampfer / Coursera-Stanford-ML-Python

Coursera/Stanford Machine Learning course assignments in python
445 stars 231 forks source link

AttributeError: 'NoneType' object has no attribute 'scatter' #8

Open xtiansimon opened 7 years ago

xtiansimon commented 7 years ago

Hello. I'm just starting the course in November. ex1.py file is giving me an error:

AttributeError: 'NoneType' object has no attribute 'scatter'

I'm a little bit of a matplotlib newbie--which is to say I can get my code to run. So maybe it's common problem you run into when publishing for the greater Python community?

Just to be sure it's not my coding skillz, I've added an example scatter plot to the plotData.py file--ya know, do nothing with the function, but, oh by the way, here's a scatter plot.

This file works fine by itself and displays the example; however, when I run ex1.py, and it calls plotData.py I get the error. I'm on Archlinux, ipython2 (5.1.0), matplotlib (1.5.3).

import datetime
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
t2=[datetime.datetime(1970,1,1),datetime.datetime(2000,1,1)]
xend = datetime.datetime.now()
yy= [0, 1]
ax.plot(t2, yy, linestyle='none', marker='s', 
    markerfacecolor='cornflowerblue', 
    markeredgecolor='black',
    markersize=7,
    label='my scatter plot')

print("lim is {0}".format(xend))
ax.set_xlim(left=datetime.datetime(1960,1,1), right=xend)
ax.set_ylim(bottom=-1, top=2)
ax.set_xlabel('Date')
ax.set_ylabel('Value')
ax.legend(loc='upper left')
fig.show()

def plotData(data):
    """
    plots the data points and gives the figure axes labels of
    population and profit.
    """

    # ====================== YOUR CODE HERE ======================
    # Instructions: Plot the training data into a figure using the
    #               "figure" and "plot" commands. Set the axes labels using
    #               the "xlabel" and "ylabel" commands. Assume the
    #               population and revenue data have been passed in
    #               as the x and y arguments of this function.
    #
    # Hint: You can use the 'rx' option with plot to have the markers
    #       appear as red crosses. Furthermore, you can make the
    #       markers larger by using plot(..., 'rx', 'MarkerSize', 10);
    # ============================================================
    #plt.figure()  # open a new figure window
    raise NotImplementedError