Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Created April 11, 2020 20:20
Show Gist options
  • Save rchardptrsn/dc3563124ee5ed85e672cd082ad85a09 to your computer and use it in GitHub Desktop.
Save rchardptrsn/dc3563124ee5ed85e672cd082ad85a09 to your computer and use it in GitHub Desktop.
# Import packages
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Indedependent variable - number of chimpanzees in hunting party
x = np.array([1,2,3,4,5,6,7,8])
# Dependent Variable - percent of successful hunts
y = np.array([30,45,51,57,60,65,70,71])
df = pd.DataFrame({'Number of Chimpanzees':x,'Percent Successful Hunts':y})
# Initialize the figure
plt.figure(figsize=(8,5))
plt.title('Number of Chimpanzees vs Hunt Success - Least Squares Line')
# Scatterplot
sns.scatterplot(x='Number of Chimpanzees',y='Percent Successful Hunts',data=df).get_figure().savefig('Chimpanzee Hunt Sucess with Least Squares Line.png')
# Least Squares Line
x = np.linspace(1,8,100)
y = 5.4405*x+31.6429
plt.plot(x, y, '-g',label='y=5.4405x+31.6429')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment