-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsea_level_predictor.py
28 lines (22 loc) · 1010 Bytes
/
sea_level_predictor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
def draw_plot():
# Read data from file
df = pd.read_csv('epa-sea-level.csv')
# Create scatter plot
plt.scatter(df['Year'], df['CSIRO Adjusted Sea Level'])
# Create first line of best fit
lr_1880_2012 = linregress(df['Year'], df['CSIRO Adjusted Sea Level'])
plt.plot(range(1880, 2051, 1), lr_1880_2012.slope * range(1880, 2051, 1) + lr_1880_2012.intercept)
# Create second line of best fit
lr_2000_2012 = linregress(df.query('Year >= 2000')['Year'],
df.query('Year >= 2000')['CSIRO Adjusted Sea Level'])
plt.plot(range(2000, 2051, 1), lr_2000_2012.slope * range(2000, 2051, 1) + lr_2000_2012.intercept)
# Add labels and title
plt.title('Rise in Sea Level')
plt.ylabel('Sea Level (inches)')
plt.xlabel('Year')
# Save plot and return data for testing (DO NOT MODIFY)
plt.savefig('sea_level_plot.png')
return plt.gca()