CBSE Class 12 Informatics Practices Question 17 of 33

Plotting with Pyplot — Question 14

Back to all questions
14
Question

Question 10

The prices of a stock for 3 months are given. Write a program to show the variations in prices for each month by 3 lines on same line chart. Make sure to add legends and labels. Show grid also.

Answer
import matplotlib.pyplot as plt
months = ['January', 'February', 'March']
prices_stock_A = [100, 120, 110]
prices_stock_B = [90, 110, 100]
prices_stock_C = [95, 115, 105]

plt.plot(months, prices_stock_A, label='Stock A', marker='o')
plt.plot(months, prices_stock_B, label='Stock B', marker='s')
plt.plot(months, prices_stock_C, label='Stock C', marker='^')
plt.xlabel('Months')
plt.ylabel('Prices')
plt.title('Stock Prices Variation')
plt.legend()
plt.grid(True)
plt.show()
Output
The prices of a stock for 3 months are given. Write a program to show the variations in prices for each month by 3 lines on same line chart. Make sure to add legends and labels. Show grid also. Plotting with Pyplot, Informatics Practices Computer Science Sumita 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.