Informatics Practices
Write a Python program to plot the function y = x2 using the Matplotlib library.
PyPlot
1 Like
Answer
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
y = x ** 2
plt.plot(x, y)
plt.title('Line Graph of y = x²')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
Output

Answered By
3 Likes
Related Questions
Write a Python program to display a horizontal bar chart of the number of students in a class.
Sample data:
Class: I, II, III, IV, V, VI, VII, VIII, IX, X
Strengths: 40, 43, 45, 47, 49, 38, 50, 37, 43, 39Plot a line graph for: y2 = 4*x
Name the various methods used with pyplot object.
Write the specific purpose of the following functions used in plotting:
(a) show()
(b) legend()