Informatics Practices
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.
PyPlot
2 Likes
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

Answered By
2 Likes
Related Questions
The score of four teams in 5 IPL matches is available to you. Write a program to plot these in a bar chart.
The score of a team in 5 IPL matches is available to you. Write a program to create a pie chart from this data, showing the last match's performance as a wedge.
A distribution data stores about 1000 random number. Write a program to create a scatter chart from this data with varying point sizes.
Navya has started an online business. A list stores the number of orders in last 6 months. Write a program to plot this data on a horizontal bar chart.