[Type A] Chapter– 8 Class 12 CS – Sumita Arora Assignment | Q/A

Here is class 12 computer science Unit 8 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 8 and for all chapters here.

Watch all tutorials for chapter 8.

Q1: What is the significance of data visualization?

Data visualization help us to have a visual representation of the data like bar, chart, map etc. It simply makes the analyses of the massive and large data in easy and appropriate manner.

It makes us to pick the trend and result out of the raw data for decision-making information.

Q2: How does Python support data visualization?

Python enables its library namely matplotlib.pyplot which having large number of effective 2D and also 3D plot for data visualization.

Q3: What is the use of matplotlib and pyplot?

matplotlib is python library that is having a numerous 2D and 3D various plotting features like bar, chart, pie, graph etc. It allows to have a visual display of the data and also publish ready figure to show results.

matplotlib having many interfaces for the visualizing of data and pyplot is one of them.

Q4: What are the popular ways of plotting data?
  • Line plot
  • scatter plot
  • histogram
  • box plot
  • bar chart
  • Pie chart etc.
Q5: What are ndarrays? How are they different from Python lists?

A ndarray refers to numpy array that is a grid of values, all of the same type, and is indexed by a tuple of non-negative integers.

 A list is the Python equivalent of an array, but is resizeable and can contain elements of different types.

Also in numpy is highly extensive management of number and highly recommendable due to good performance than list.

Q6: Compare bar() and barh() functions?

pyplot offer a function bar() for plotting bar graph of vertical and horizontal orientation but by default it plots vertical bar graph of various length and visual bars.

barh() is a function of pyplot that plot horizontal bar graph in specific manner.

Q7: What is the role of legends in a graph/chart?

When we are plotting various plot in same figure of different feature by giving separate label to them than legend() function enable to publish the title at given position to distinguishing the separate feature plot by various parameter (colour, shape, style etc.)

Q8: What will happen if you use legend() without providing any label for the data series being plotted?

In this a warning will arise i.e. “No handles with labels found to put in legend“.

Q9: What do you understand by xlimit and ylimit? How are these linked to data being plotted?

xlimit and ylimit are function of pyplot that just shrink or limit the x-axis and y-axis plot to the given parameter in the function call.

plt.xlim([20,80]) #this will display x-axis in between 20 to 80
plt.ylim([5.0, 15.0])   #this will display y-axis in between 5 to 15
Q10: When should you use – a line chart, a bar chart, and a pie chart?

Line graphs can also be used to compare changes over the same period of time for more than one group.
Pie charts are best to use when we are trying to compare parts of a whole.
Bar graphs can be used where we want a tally record of same thing over a long period.

Q11: Write code in python to create a lists L1 having even elements between 1-10. Create another list L2 that stores the cubes of elements of list L2.
L1 = list(range(0,11,2))
L2 = [i*3 for i in L1]

Q12: Repeat the previous question but this time use numpy functions to create the two sequences.
L1 = np.array((range(0,11,2)))
L2 = numpy.array(L1)*3
Q13: A list temp contains average temperatures for seven days of last week. You want to see how the temperature changes I last seven days. Which chart type will you plot for the same and why?

Bar graph and scatter plot can be choice for this plot as it will give a comparative view of temperature on the seven days of the last week. Most preferable bar graph will be opted.

Q14: Write code to practically produce a chart for question 8.
import matplotlib.pyplot as plt
simple = []
curve = []
higher_curve = []
for i in range(20):
    simple.append(i)
    curve.append(i*2) 
    higher_curve.append(i*3)
plt.plot(list(range(20)), simple )
plt.plot(list(range(20)), curve)
plt.plot(list(range(20)),higher_curve)
plt.legend()
plt.show()
Q15: A company has three offices across India: Delhi, Mumbai, Kolkata. Each of the offices has sent a compiled list sharing sales in quarter1, quarter2, quarters, and quarter4.
(a) suggest the best chart type to plot all the above data?
(b) Why did you choose that specific chart type?
(c) Can you create a pie chart from above data?

(a) A bar graph will be an appropriate way to plot the data.

(b) In this a direct compare of the all quarter for various company will de done easily.

(c) Yes, we can have three pie charts each for the different city branch.

Q16: Write code to produce a chart plotting all the data given in question 10.
import matplotlib.pyplot as plt
import numpy as np

curve = []
for i in range(20):
    curve.append(i*2)

#Line chart
plt.plot(list(range(20)), curve)
plt.show()

#bar graph
plt.bar(list(range(20)), curve)
plt.show()

#pie chart
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
plt.pie(students, labels = langs,autopct='%1.2f%%')
plt.show()

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

You cannot copy content of this page