Write a Python program to plot the function y = x*x using the pyplot or matplotlib libraries.
- Details
- Category: 12th class computer practical's.
- Published: Friday, 11 June 2021 08:05
- Written by Super User
- Hits: 323
import matplotlib.pyplot as plt
x_coordinates=range(-20,20,1)
y_coordinates=[x*x for x in x_coordinates]
plt.plot(y_coordinates,x_coordinates)
plt.show()
Explanation: In this program we are importing pyplot class from python. pyplot library is part of matplotlib library. matplotlib is used to create mapping functionality and different types of Maps, graphs and charts. this library is used for various reporting, analytics and dashbaording functions.
x_coordinates variable is storing range object for x axis plotting points on graph. y_coordinates is getting all y points for plotting against x points range. plot function of pyplot object plots the points using corresponding range objects. plt.show() function shows the graph on screen.
It is a example of simple graph equation y=x2 . This way we can plot any graph equation.