0% found this document useful (0 votes)
10 views

Data Visualization 2 ip

very useful notes

Uploaded by

madhavmanoj08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Data Visualization 2 ip

very useful notes

Uploaded by

madhavmanoj08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

>>> Classes = ['IX', 'X', 'XI', 'XII']

>>> STD = [290, 315, 350, 300]


>>> pl.bar(Classes,STD)
<BarContainer object of 4 artists>
>>> pl.show()
Customising Bar Chart
pl.bar(Classes,STD,width=[.2,.4,.6,.3],color=['red','green','blue',
'y'],edgecolor='white',linewidth=2,linestyle='--')
Q. Write a Python program to draw line and Bar charts from the given financial data of ABC Co.
for 5 days in the form a DataFrame namely fdf as shown below :

Day1 Day2 Day3 Day4 Day5


0 74.25 56.03 59.30 69.00 89.65
1 76.06 68.71 72.07 78.47 79.65
2 69.50 62.89 77.65 65.53 80.75
3 72.55 56.42 66.46 76.85 85.08

>>> import matplotlib.pyplot as pl


>>> import pandas as pd
>>> x = {"Day1": [74.25, 76.06, 69.50, 72.55],\
"Day2": [56.03, 68.71, 62.89, 56.42],\
"Day3": [59.30, 72.07, 77.65, 66.46],\
"Day4": [69.00, 78.47, 65.53, 76.85],\
"Day5": [89.65, 79.65, 80.75, 85.08]}
>>> df=pd.DataFrame(x)
>>> df.plot()
>>> pl.show()
import pandas as pd
import matplotlib.pyplot as plt
x = {"Day1": [74.25, 76.06, 69.50, 72.55],\
"Day2": [56.03, 68.71, 62.89, 56.42],\
"Day3": [59.30, 72.07, 77.65, 66.46],\
"Day4": [69.00, 78.47, 65.53, 76.85],\
"Day5": [89.65, 79.65, 80.75, 85.08]}

df1=pd.DataFrame(x)
df1.plot.bar()
plt.show()
Q. Given a data frame df1 as shown below:

1990 2000 2010


a 52 340 890
b 64 480 560
c 78 688 1102
d 94 766 889

Write code to create:


(a) A scatter chart from the 1990 and 2010 columns of dataframe df1
(b) A line chart from the 1990 and 2000 columns of dataframe df1
(c) Create a bar chart plotting the three columns of dataframe dfl
>>> import matplotlib.pyplot as pl
>>> import pandas as pd
>>> d={1990:[52,64,78,94],2000:[340,480,688,766],2010:[890,560,1102,889]}
>>> df1=pd.DataFrame(d)
>>> df1.plot.scatter(x = 1990, y = 2010);
>>>pl.show()

>>> d={1990:[52,64,78,94],2000:[340,480,688,766],2010:[890,560,1102,889]}
>>> df1=pd.DataFrame(d)
>>> df1.plot(x = 1990, y = 2000,marker=‘D’, markersize=7);
>>>pl.show()
import pandas as pd
import matplotlib.pyplot as plt
d={1990:[52,64,78,94],2000:[340,480,688,766],2010:[890,560,1102,889]}
df1=pd.DataFrame(d)
df1.plot.bar()
plt.show()
Q. Given a data frame df as shown below:

IP CS ENG
2019 90 92 89
2020 91 81 91
2021 97 96 88
Write code to create bar chart of the above with different-2 color as (Red, Blue and Yellow).
import matplotlib.pyplot as plt
import pandas as pd
record={'IP': pd.Series([90, 91, 97], index=['2019','2020','2021']),
'CS': pd.Series([92, 81, 96], index=['2019','2020','2021']),
'ENG': pd.Series([89, 91, 88], index=['2019','2020','2021'])}
S=pd.DataFrame(record)
print(S)
S.plot.bar(color=['red','blue','yellow'],edgecolor='white',linewidth=2,linestyle='--')
plt.show()
Country Gold Silver Bronze Total
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
New 15 16 15 46
Zealand
South 13 11 13 37
Africa
Wales 10 12 14 36
Scotland 9 13 22 44
Nigeria 9 9 6 24
Cyprus 8 1 5 14

You might also like