Python ProgrammingPython Programming

How to plot a line graph in Matplotlib?

Plot a line graph:

In this example we had passed only one list of two points, which will be taken as y axis co-ordinates. For x axis it takes the default values in the range of 0 to 1, 2 being the length of the list [5, 15].

import matplotlib.pyplot as plt

#Plot a line graph
plt.plot([5, 15])

# Add labels and title
plt.title("Interactive Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()