# Matplotlib: Plot

The plot() function plots the $y$ versus $x$ graph as lines and/or markers. It is one among the many command-like functions of the matplotlib.pyplot interface. The typical examples of the $y$ vs $x$ graphs we come across in school are the distance-time graphs (distance along the $y$-axis, time along the $x$-axis), speed-time graphs, period-length graphs of a simple pendulum, etc. In this tutorial, we pick the temperature-time graphs to plot using the plot() function.

Consider the monthly average temperatures (°C) in Singapore, as given by https://www.holiday-weather.com/. We represent them in a one-dimensional array.

[26,27,27,27,27,27,27,27,27,27,26,26]

We provide this array as a single argument to the plot() function in the program below.

import matplotlib.pyplot as plt
plt.plot([26,27,27,27,27,27,27,27,27,27,26,26])
plt.ylabel('Temperature (°C)')
plt.show()

Matplotlib assumes this to be the set of values along the $y$-axis (ordinates) and auto creates the $x$ values of the same length. Save this program as temperature.py inside some directory, say, /python-programs. Next, navigate to the /python-programs directory and run it.