Q. 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

X = [ "Month 1" ,"Month 2" ,"Month 3"   ]

a = [ 52, 34, 89]
b = [ 64, 48, 56]
c = [ 78, 68, 25 ]


plt.xlabel("Months")
plt.ylabel("Stock Price")
plt.plot(X,a, label = "Path Stock")
plt.plot(X,b, label = "Walla Stock")
plt.plot(X,c, label = "Portal Stock")
plt.grid(True)
plt.legend ( loc = "upper left")

plt. show()


Output :-



Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post