* # Read in the data. mlb = loadtxt('mlb.txt', dtype=[('team', 'S3'), ('w', 'i'), ('l', 'i'), ('pct', 'f'), ('rdiff', 'i')]) # Plot the data with invisible points. scatter(mlb['rdiff'], mlb['w'], s=0) xlabel('Run differential') ylabel('Wins') # Put team names at the data points. for (t, w, rd) in zip(mlb['team'], mlb['w'], mlb['rdiff']): text(rd, w, t, size=9, horizontalalignment='center', verticalalignment='center') # Perform the linear regression m, b, r, p, stderr = stats.linregress(mlb['rdiff'], mlb['w']) # Get endpoints of regression line and plot it. rdMin = min(mlb['rdiff']) wMin = m*rdMin + b rdMax = max(mlb['rdiff']) wMax = m*rdMax + b plot([rdMin, rdMax], [wMin, wMax]) show()