CBSE Class 12 Informatics Practices Question 8 of 27

Data Visualization using Matplotlib — Question 9

Back to all questions
9
Question

Question 9

Write a Python program to plot two or more lines with legends, different widths and colors.

Answer
import matplotlib.pyplot as plt
x1 = [10,20,30]
y1 = [20,40,10]
plt.plot(x1, y1, color='blue', linewidth=3, label='line1')
x2 = [10,20,30]
y2 = [40,10,30]
plt.plot(x2, y2, color='red', linewidth=4, label='line2')
plt.legend()
plt.show()
Output
Write a Python program to plot two or more lines with legends, different widths and colors. Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12
Get the Bright Tutorials app Stuck on a question? Ask Bright Buddy — your AI tutor — for step-by-step help in the app.