# Best 40+ Python Matplotlib Class 12 IP Question Answer

Share with others

## Python Matplotlib Class 12 IP Question Answer

Python Matplotlib Class 12 IP Question Answer

## Q1. What do you mean by Data Visualisation?

Ans. Data visualisation means graphical or pictorial representation of the data using graph, chart, etc.

## Q2. Give two examples of visualisation that we come across in our daily lives.

Ans. Traffic symbols, ultrasound reports, Atlas book of maps, speedometer of a vehicle, tuners of instruments are examples of visualisation that we come across in our daily lives.

Ans. Matplotlib

## Q4. Write short note on Matplotlib.

Ans. Matplotlib library is used for creating static, animated, and interactive 2D- plots or figures in Python. It can be installed using the following pip command.

pip install matplotlib

Ans. Pyplot

## Q6. Write a statement to import pyplot module of matplotlib library.

Ans. import matplotlib.pyplot as plt

Here, plt is an alias or an alternative name for matplotlib.pyplot. We can use any other alias also.

Ans. plot()

Ans. show()

## Quantity = [10, 7, 20]

```Ans.

import matplotlib.pyplot as plt
Name = ["Keyboard", "RAM", "Mouse"]
Quantity = [10, 7, 20]
plt.plot(Name, Quantity)
plt.show()```

## Q10. Write two ways of saving the chart or figure created in python using pyplot.

Ans. Two ways are:

1. We can click on the save button on the output window and save the plot as an image.
2. A figure can also be saved by using savefig() function.

Ans. savefig()

## Q12. Which Pyplot functions is used to plot bar chart and histogram? Write the statement also.

Ans. bar() is used to create bar chart and hist() is used to create histogram.

plt.bar( ) #plt is an alias pf pyplot module

plt.hist( ) #plt is an alias pf pyplot module

## Q13. Which pyplot functions are used to customise the following components of plot?

3. To add label of X-axis
4. To add label of Y-axis

Ans.

## Q14. Name any four parameters of plot( ) function.

Ans. Four parameters of plot() function are:

1. Marker
2. Colour
3. linestyle
4. linewidth

## Q15. What do you mean by marker attribute of plot() function?

Ans. A marker is any symbol that represents a data value in a line chart or a scatter plot.

## Q16. What is the purpose of colour attribute of plot() function?

Ans. Colour attribute help to format the plot by changing the colour of the plotted data. We can either use character codes or the color names as values to the parameter color in the plot().

1. ‘b’
2. ‘m’
3. ‘k’
4. ‘c’

Ans.

## Q18. Which attribute of plot() function are used to change the width and the style of the line chart?

Ans. linewidth and linestyle attribute of plot() function are used to change the width and the style of the line chart respectively.

Ans. Pixel, One

## Q20. Write any four string values that linestyle parameter of plot() function can take.

Ans. Four values of linestyle parameter are:

1. “solid”
2. “dotted”
3. “dashed”
4. “dashdot”

Ans. S1.plot( )

Ans. Values are

1. line
2. bar
3. hist
4. barh

## Q23. What do you mean by line chart? Explain in brief.

Ans. A line plot is a graph that shows the frequency of data along a number line. It is used to show continuous
dataset. A line plot is used to visualise growth or decline in data over a time interval.

## Q24. What are some of the major components of any graphs or plot?

Ans. Major components of graphs are:

1. Chart Title
2. X-axis
3. Y-axis
4. X – axis Title
5. Y – axis Title
6. Legend

## Q25. What is the purpose of a legend?

Ans. A legend is used to identify data in visualizations by its color, size, or any other distinguishing features.

## Q26. What is open data? Name any two websites from which we can download open data.

Ans. Data which is freely available for anyone to download and do analysis, primarily for educational purposes. These are called Open Data as the data source is open to the public.

## Q27. Dhriti wants to plot a line chart based on the given data to view the changing weekly average temperature for four weeks. Help her to write the code in Python. Also give appropriate chart title and axis titles.

Week = [1, 2, 3, 4]

Temp = [30, 34, 28, 32]

```Ans.

import matplotlib.pyplot as plt
Week=[1, 2, 3, 4]
Temp =[30, 34, 28, 32]
plt.plot(Week, Temp)
plt.title("Change in Temperature Weekly")
plt.xlabel("Week")
plt.ylabel("Temperature")
plt.xticks(Week)
plt.show()
```

## Also give suitable python statement to save this chart.

```Ans.

import matplotlib.pyplot as plt
medalsnumber = [8, 6, 4, 5]
plt.bar(sport, medalsnumber)
plt.xlabel("Sports Name")
plt.ylabel("Medals Number")
plt.title("Medals Tally")
plt.show()
plt.savefig("sports.jpg") #statement to save the chart```

## Q29. Write a Python program to display a bar chart for the following Data. Also give appropriate chart title and axis lables.

Name = [“Amit”, “Sunil”, “Ravi”, “Sonal”]

Marks_in_PT1 = [20, 12, 25, 28]

## Also give suitable python statement to save this chart

```Ans.

import matplotlib.pyplot as plt
Name = ["Amit", "Sunil", "Ravi", "Sonal"]
Marks_in_PT1 = [20, 12, 25, 28]
plt.bar(Name, Marks_in_PT1)
plt.title("Marks in Periodic Test")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.show()
plt.savefig("results.jpg") #statement to save the chart
```

## Also give suitable python statement to save this chart

```Ans.

import matplotlib.pyplot as plt
classes = ["VI", "VII", "VIII", "IX", "X", "XI"]
average_percentage = [70, 75, 65, 80, 78, 68]
plt.bar(classes, average_percentage)
plt.title("Class wise Result Analysis-Average Percentage")
plt.xlabel("Student Class")
plt.ylabel("Average Percentage")
plt.show()
plt.savefig("average.jpg") #statement to save the chart
```

## Also give suitable python statement to save this chart

```Ans.

import matplotlib.pyplot as plt
month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sales = [10, 7, 8, 9, 6, 9]
plt.bar(month, sales)
plt.title("Month wise Sales")
plt.xlabel("Month")
plt.ylabel("Sales(in Lakhs)")
plt.show( )
plt.savefig("sales.jpg") #statement to save the chart
```

## Also give suitable python statement to save this chart.

```Ans.

import matplotlib.pyplot as plt
Med_Name=["Crocin", "Cough-Syrup", "Cetirizine", "Azithromycin"]
No_of_strips =[4, 6, 2, 3]
plt.plot(Med_Name, No_of_strips)
plt.title("Number of Medicine Strip available")
plt.xlabel("Medicine Name")
plt.ylabel("Number of Strips")
plt.yticks([1, 2, 3, 4, 5, 6])
plt.show()
plt.savefig("medicine.jpg") #statement to save the chart
```

## Also give suitable python statement to save this chart.

```Ans.

import matplotlib.pyplot as plt
A = [0.2, 0.4, 0.6, 0.8, 1.0]
V = [0.5, 1.0, 1.5, 2.0, 2.5]
plt.plot(A, V, marker="*")
plt.title("Relationship between Potential difference and Current")
plt.xlabel("Current ----->")
plt.ylabel("Voltage ----->")
plt.xticks(A)
plt.yticks(V)
plt.show( )
plt.savefig("current.jpg") #statement to save the chart

```

## Also give suitable python statement to save this chart.

```Ans.

import matplotlib.pyplot as plt
college_name = ["KM", "DDU", "LSR", "JD", "DS"]
pol_sc_seats = [160, 220, 150, 200, 180]
plt.bar(college_name, pol_sc_seats, edgecolor="red")
plt.title("Number of seats in DU College")
plt.xlabel("College Name")
plt.ylabel("No. of Seats in Pol. Sc.")
plt.show()
plt.savefig("seats.jpg") #statement to save the chart
```

## She wants to read the data from data.csv and draw the line chart as shown below. Help her in writing the code.

```Ans.

import pandas as pd
import matplotlib.pyplot as plt
df.plot(kind='line', x='Month', color=['red', 'blue'])
plt.title('Year-Wise Sales')
plt.xlabel('Months')
plt.ylabel('Sales')
plt.show()
```

## Q36. Parth is a student of class XII. He wants to represent the following data in the bar chart with label “Fruit Name” on X-axis and “Monthly Expenditure” on Y-axis. He wants that edge color of the bar should be “red”. Help him to write the code.

```Ans.

import matplotlib.pyplot as plt
fruit = ["Banana", "Apple", "Grapes", "Papaya", "Melon"]
cost = [300, 600, 500, 740, 450]
plt.bar(fruit, cost, edgecolor="red")
plt.title("Monthly Expenditure on Fruits")
plt.xlabel("Fruit Name")
plt.ylabel("Monthly Expenditure")
plt.show( )
```

## Q37. Write a python program to plot a line chart based on the given data with suitable axes label and chart title.

Team = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]

Wins = [5, 3, 6, 2, 7]

## Also give suitable python statement to save this chart.

```Ans.

import matplotlib.pyplot as plt
Team = ['A', 'B', 'C', 'D', 'E']
Wins = [5, 3, 6, 2, 7]
plt.plot(Team, Wins)
plt.title("Matches Wins - Team Wise")
plt.xlabel("Team")
plt.ylabel("Wins")
plt.show()
plt.savefig("win.jpg")
```

## Q38. Sudha is working in a multinational company. She has to present the following data in line chart with the following specification.

1. Series Name should be on X-axis
2. Line represents India — Green Colour
3. Line represents Pakistan — Red Colour
4. Chart Title: “Series Comparison between India and Pakistan”
5. X-axis Label: “Series Name”
6. Y-axis Label: “Matches Played”
```Ans.

import matplotlib.pyplot as plt
series = ["Pataudi", "Kapil", "Gavaskar", "Imran", "Shane"]
india =[15, 20, 18, 9, 5]
pak = [10, 15, 12, 15, 8]
plt.plot(series,india,'g')
plt.plot(series,pak,'r')
plt.title("Series Comparison between India and Pakistan")
plt.xlabel("Series Name")
plt.ylabel("Matches Played")
plt.show()
```

## Q39. Aman is a Sports Captain in GTBP School. He wants to represent the following data in line chart with the specifications given below.

Number of Goals scored by three schools in four Matches

1. Matches should be displayed on X-axis.
2. Line represent School-1 — Blue
3. Line represent School-2 — Black
4. Line represent School-3 — Red
5. Y-axis Label: “No. of Goals Scored”
6. X-axis Label: “Matches”
7. Chart Title — “Number of Goals scored by three schools”
```Ans.

import matplotlib.pyplot as plt
match = ["Match-A", "Match-B", "Match-C", "Match-D"]
school_1 = [5, 3, 4, 1]
school_2 = [4, 2, 1, 0]
school_3 = [6, 4, 5, 2]
plt.plot(match, school_1, 'b')
plt.plot(match, school_2, 'k')
plt.plot(match, school_3, 'r')
plt.title("Number of Goals scored by three schools")
plt.xlabel("Matches")
plt.ylabel("No. of Goals Scored")
plt.legend()
plt.show()
```

## Q40. Suman is a data analyst. She has the following data in a csv file named “year.csv”. Her boss asked Suman to represent data in the form of bar chart. Help her in reading csv file and in creating bar chart with the following specification.

1. Chart Title: Department wise Expenditure
2. X-Axis Label: Departments
3. Y-Axis Label: Expenditure(in Rs)
4. Department should be displayed on X-axis
5. Colour of bar should be RED
```Ans.

import matplotlib.pyplot as plt
import pandas as pd
df.plot(kind="bar",x="Department", color="red")
plt.title("Department wise Expenditure")
plt.xlabel("Departments")
plt.ylabel("Expenditure(in Rs)")
plt.show()
```

## Q41. Anant is working as a Data Analyst in a company named “”Compu-Tech”. He stored the following data in a file named “emp.csv”. He wants to present “Department” (First Column) and “No_of_Emp” (Third Column) in a bar chart. Help him to write the code.

1. Chart Title: Compu-Tech Employee Data
2. X-Axis Label: Departments
3. Y-Axis Label: Number of Employees
4. Department should be displayed on X-axis
5. Colour of bar should be RED
```Ans.

import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("monthsales.csv", usecols = ['Department', 'No_of_Emp'])
df.plot(kind = "bar", x = "Department", color = "red", )
plt.title("Compu-Tech Employee Data")
plt.xlabel("Departments")
plt.ylabel("Number of Employees")
plt.show()
```

## Q42. Write python code to plot a bar chart shown below. Colour of each bar is given below:

• UP – Black
• AP – Magenta
• Kerala – Cyan
• Gujarat – Green
• Punjab – Yellow
```Ans.

import matplotlib.pyplot as plt
state = ["UP", "AP", "Kerala", "Gujarat", "Punjab"]
wickets = [12, 22, 18, 15, 8]
plt.bar(state, wickets, color=['k', 'm', 'c', 'g', 'y'])
plt.title("Ranji Trophy")
plt.xlabel("State-Teams")
plt.ylabel("Wickets")
plt.yticks(wickets)
plt.show()```

## Q43. Aman is the head boy of a reputed school in Delhi. He wants to plot a bar chart for the data given below. He also wants that each bar should be of same colour as of house colour. Help him to write the code in Python to create bar chart with appropriate chart title and both axis labels.

house = [“Red”, “Green”, “Yellow”, “Blue”]

medals = [42, 35, 51, 46]

```Ans.

import matplotlib.pyplot as plt
house = ["Red", "Green", "Yellow", "Blue"]
medals = [42, 35, 51, 46]
plt.bar(house, medals, color=['r','g','y','b'])
plt.title("House-Wise Medals Count")
plt.xlabel("Houses")
plt.ylabel("Medals")
plt.show( )```

## MCQ of Computer Science Chapter Wise

1. Functions in Python

2. Flow of Control (Loop and Conditional statement)

3. 140+ MCQ on Introduction to Python

4. 120 MCQ on String in Python

5. 100+ MCQ on List in Python

6. 50+ MCQ on Tuple in Python

7. 100+ MCQ on Flow of Control in Python

8. 60+ MCQ on Dictionary in Python

## 70 Practice Questions on if-else

Disclaimer : I tried to give you the simple and important questions of ”Data Visualisation using Python Matplotlib” , but if you feel that there is/are mistakes in the code or explanation of “Data Visualisation using Python Matplotlib“ given above, you can directly contact me at csiplearninghub@gmail.com. Reference for the questions created above is NCERT book and CBSE Sample Paper.

## Python Matplotlib Class 12 IP Question Answer

Share with others
error: Content is protected !!