Learn

Recreate Graphs using Matplotlib!

Line with Shaded Error

Now, we are going to look at the chart called `line_graph.png`

. This displays the relationship between the time students say they studied and the scores they received on their final exams.

The data you will need to recreate this chart is in the lists `hours_reported`

and `exam_scores`

.

Save your recreated chart to a file called `my_line_graph.png`

.

Create a figure of width `10`

and height `8`

.

Plot the `exam_scores`

on the x-axis and the `hours_reported`

on the y-axis, with a `linewidth`

of `2`

.

Letâ€™s assume the error on studentsâ€™ reporting of their hours studying is 20%.

Create a list `hours_lower_bound`

, which has the elements of `hours_reported`

minus 20%, and a list `hours_upper_bound`

, which has the elements of `hours_reported`

plus 20%.

You can do this with a list comprehension that looks like:

`y_lower_bound = [element - (element * error_in_decimal) for element in original_list_of_y_values]`

Shade the area between `hours_lower_bound`

and `hours_upper_bound`

with an alpha of `0.2`

.

Give the plot the title `'Time spent studying vs final exam scores'`

, x-axis label `'Score'`

, and y-axis label `'Hours studying (self-reported)'`

.

Save your figure to a file called `my_line_graph.png`

.