Summary

In this lecture we will make a summary of what we learned so far. We will do this by explaining the following code. The code contains all the code elements that we covered.

 Line 1: After having done some internet research we found out that we can use the Python matplotlib library to generate plots with Python. Looking at the matplotlib documentation we find out that we can use the pyplot object to generate a plot. Therefore, we import pyplot in the first line.

 Line 2: In this line we import a greeting message, but this is not important. We can delete that line.

Line 5 and 6: To make a graph you need data. Here we create two lists. One contains the dates for the x-axis and the other contains the temperatures for each date. It is important that the two lists have the same number of items. Otherwise, you will get an error when you run the code.

Line 8: Here we simply print out the maximum temperature. The max function finds out the maximum, and the print function prints it out.

Line 10-12: Remember, in line 1 we imported pyplot. For now, pyplot is just an empty plot. In these lines, we add a title to that plot and labels to its x and y axes. 

Line 14 and 15: In line 14, we plot the dates and the temperatures along the x and the y axes, respectively. We do that by providing the variables that contain the two data lists as arguments for the plot method. In line 15, we display the plot in the output pane. 

That's it. Using a combination of objects, variables, functions, and methods, we were able to generate a plot. With practice you will learn to use those code elements to create any type of Python program. Keep learning! Start the next level course of Python in this link: https://pythonhow.com/learning-python/intermediate

Recommended Course

Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.