You are on page 1of 2

ALGORITHM

1. Import csv file from the files.


2. Convert the data of the csv file into dataframe.
3. Printing dataframes of both the companies.
4. Setting compamies data frame name .
5. Giving the size of the figure
6. Arange the value to 20 using numpy
7. Plotting the bar graph for infosys
8. Ploting the bar graph for hcl
9. Plot xticks
10. Ploting legend at location 2
11. Giving title
12. Ploting xlabel
13. Ploting ylabel
14. Plotting the graphs color
15. Plotting the graphs color

CODE

from matplotlib import pyplot as plt

import pandas as pd
import numpy as np

df=pd.read_csv(r'A:\3RD sem\python\comp.csv')

dataf=pd.DataFrame(df,columns=["date","Infosys","hcl"]) #converting csv file data into dataframes

print(dataf) #printing dataframes

Companies=["Infosys","hcl"] #name of the comapny

plt.figure(figsize=(25,10)) #giving the size of the figure

a=np.arange(20) #arange the value to 20 using numpy

plt.bar(a+0.00,dataf["Infosys"],color='navy',width=0.25) #plotting the bar graph for infosys

plt.bar(a+0.25,dataf["hcl"],color='orchid',width=0.25) #ploting the bar graph for hcl

plt.xticks(a,dataf["date"]) #plot xticks

plt.legend(Companies,loc=2) #ploting legend at location 2

plt.title("comparison of stocks price ",fontsize=18) #giving title

plt.ylabel('closing price',fontsize=16) #ploting xlabel

plt.xlabel('date',fontsize=16) #ploting ylabel

plt.plot(dataf["date"],dataf["Infosys"],color='navy') #plotting the graphs color

plt.plot(dataf["date"],dataf["hcl"],color='orchid') #plotting the graphs color

plt.show() #show the plots

REFERENCE OF DATA OF BANKS :

https://in.finance.yahoo.com/quote/INFY.NS/history?p=INFY.NS for Infosys

https://in.finance.yahoo.com/quote/HCLTECH.NS/history?p=HCLTECH.NS for hcl

CODE CONSOLE

You might also like