import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
"""
Create matrix of ones
"""
a = np.ones((5,10))
# end
"""
Make a scatter plot where y weakly depends on x
Compute the correlation coefficient
Put r^2 in a text box at the top left
Save to correlation.png
"""
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
"""
Create matrix of ones
"""
a = np.ones((5,10))
# end
"""
Make a scatter plot where y weakly depends on x
Compute the correlation coefficient
Put r^2 in a text box at the top left
Save to correlation.png
"""
x = np.random.rand(100)
y = x + np.random.rand(100)
plt.scatter(x,y)
plt.text(0.1,0.9,'r^2 = %.2f' % np.corrcoef(x,y)[0,1]**2,transform=plt.gca().transAxes)
plt.savefig('correlation.png')
Go to Google Form