Matplotlib – Line Graph

To draw a line graph in Matplotlib, use the plot() method. By default, plot() creates a line. The points used are the x and y coordinates of a line. Before moving further, we’ve prepared a video tutorial to plot a line graph in Matplotlib:

Example

Let us see an example wherein we will plot the x and y points:

import matplotlib.pyplot as plt
import numpy as np

# Data to plot a line
xPts = np.array([1, 9])
yPts = np.array([4, 12])

# Plot a line graph using the pyplot.plot() method
# The two parameters are x and y axis
plt.plot(xPts, yPts)

# Display the figure
plt.show()

Output

Line Graph in Matplotlib


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Change the font size of Matplotlib legend
Matplotlib - Scatter Plot
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment