0% found this document useful (0 votes)
9 views3 pages

Visual - Wrksht-2 (With Solutions)

Uploaded by

piyushshah16op
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Visual - Wrksht-2 (With Solutions)

Uploaded by

piyushshah16op
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CLASS XII INFORMATICS PRACTICES

Data Visualization worksheet-2


Q1. Give an example to explain the difference between vertical and Horizontal bar graphs.
Q2. WAP to create a data frame to store the average marks in physics, chem and English subjects of
4 science sections where section names are the indexes. Write code to plot the average marks of all
the three subjects as a bar graph
Ans: import pandas as pd
import matplotlib.pyplot as p
data={"phy":[90,89,95,75],
"chem":[60,40,55,30],
"English":[75,82,85,60]
}
df1=pd.DataFrame(data,index=["B","D","F","G"])
df1.plot(kind='bar', color=['blue','green','magenta'])
p.title('Average Marks Comparison of all Science sections')
p.xlabel('Sections')
p.ylabel('Marks')
p.show()

Q3 What will be the output of the following code?


import matplotlib.pyplot as p
city=["Delhi","Mumbai","Bengaluru","Kolkata"]
accident=[60,40,55,30]
p.bar(city,accident, color="orange", edgecolor="black")
p.title('Accident Tally of 4 Metropolitan cities')
p.xlabel('City')
p.ylabel('Accidents')
p.show()

Ans:

Q4. Draw the following bar graph representing the number of students in each class.

Give appropriate title and labels to both axis.


Ans:
import matplotlib.pyplot as p
clas=["VII","VIII","IX","X"]
enroll=[40,45,35,43]
p.bar(clas,enroll)
p.title('Number of Enrollments in various classes ')
p.xlabel('Class')
p.ylabel('Enrollments')
p.show()

Q5. What changes do I make in the code of Q3 so that my output shows horizontal bars?
Ans: import matplotlib.pyplot as p
city=["Delhi","Mumbai","Bengaluru","Kolkata"]
accident=[60,40,55,30]
p.barh(city,accident, color="orange", edgecolor="black")
p.title('Accident Tally of 4 Metropolitan cities')
p.xlabel('Accidents')
p.ylabel('City')
p.show()

Q6. WAP to store the following data in a dataframe, making the city names as the index. And then
plot one bar graph to show the number of number of active cases and total cases for all cities and
another bar graph to show the active cases and the number of deaths.
Cities total active death
Maharashtra 15,00,000 45000 11,000
Karnataka 12,00,000 38000 8,000
Kerala 8,00,000 25000 10,000

Ans:
import matplotlib.pyplot as plt
import pandas as pd
dict1={'total':[1500000,1200000,800000],
'active':[45000,38000,25000],
'death':[11000,8000,10000]
}
df=pd.DataFrame(dict1, index=['Maharashtra','Karnataka','Kerala'])
df[['total','active']].plot(kind='bar', color=['green','black'])
plt.title("Comparison of Active corona cases across various cities",fontsize=14,color="blue")
plt.xlabel("City",fontsize=14,color="red")
plt.ylabel("Corona Cases",fontsize=14,color="red")
plt.xticks(fontsize=10, rotation=30)
plt.show()
df[['active','death']].plot(kind='bar', color=['red','yellow'])
plt.title("Comparison of deaths of corona cases across various cities",fontsize=14,color="blue")
plt.xlabel("City",fontsize=14,color="red")
plt.ylabel("Corona Cases",fontsize=14,color="red")
plt.xticks(fontsize=10, rotation=30)
plt.show()

Output 1:
Output 2:

Q7. Fill in the blank with the correct statement to plot a bar graph using a matplotlib method, so
that Company ABC can see the graphical presentation of its profit figures for the 2 nd quarter of the
financial year 2019 (ie, Aug, sep, Oct, Nov).
import matplotlib.pyplot as mtp
Months=[‘AUG’,’SEP’,’OCT’,’NOV’] #X Axis
Profits=[125,220,230,175] #Y Axis
_____________________________________________
mtp.show()
Ans 7.
import matplotlib.pyplot as mtp
Months=['AUG','SEP','OCT','NOV'] #X Axis
Profits=[125,220,230,175] #Y Axis
mtp.bar(Months,Profits)
mtp.show()

You might also like