File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 4
4
5
5
def draw_plot ():
6
6
# Read data from file
7
-
7
+ df = pd .read_csv ('epa-sea-level.csv' )
8
+ x = df ['Year' ]
9
+ y = df ['CSIRO Adjusted Sea Level' ]
8
10
9
11
# Create scatter plot
10
-
12
+ plt . scatter ( x , y )
11
13
12
14
# Create first line of best fit
13
-
15
+ line1 = linregress (x , y )
16
+ x_pred1 = pd .Series ([i for i in range (1880 ,2051 )])
17
+ y_pred1 = line1 .slope * x_pred1 + line1 .intercept
18
+ plt .plot (x_pred1 , y_pred1 , 'r' )
14
19
15
20
# Create second line of best fit
16
-
21
+ newdf = df .loc [df ["Year" ] >= 2000 ]
22
+ x_new = newdf ['Year' ]
23
+ y_new = newdf ['CSIRO Adjusted Sea Level' ]
24
+ line2 = linregress (x_new , y_new )
25
+ x_pred2 = pd .Series ([i for i in range (2000 ,2051 )])
26
+ y_pred2 = line2 .slope * x_pred2 + line2 .intercept
27
+ plt .plot (x_pred2 , y_pred2 , 'b' )
17
28
18
29
# Add labels and title
19
-
30
+ plt .title ('Rise in Sea Level' )
31
+ plt .xlabel ('Year' )
32
+ plt .ylabel ('Sea Level (inches)' )
20
33
21
34
# Save plot and return data for testing (DO NOT MODIFY)
22
35
plt .savefig ('sea_level_plot.png' )
You can’t perform that action at this time.
0 commit comments