CBSE Class 12 Informatics Practices Question 49 of 73

Data Visualization using Matplotlib — Question 14

Back to all questions
14
Question

Question 14

Write a Python program to plot the function y = x2 using the Matplotlib library.

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
Write a Python program to plot the function y = x^2 using the Matplotlib library. Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12