Informatics Practices · Class 12 Optional
Ch 4Plotting Data using Matplotlib — Class 12 Informatics Practices, concept-first.
We have already seen how to organise and analyse data using Pandas and NumPy. But analysis alone is not always enough. When you look at a table of numbers, patterns can be hard to spot. That is where visualisation comes in.
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
Matplotlib Plotting Basics
You already understand a graph. When you see a line going up on a news chart, you know sales are rising. When you see a bar taller than another, you know one category is bigger. That instinct is all you need.
Most relevant Q&A
- (Program 4-1: Plotting Temperature against Height) In a city, the maximum temperature of a day is recorded for three consecutive days. Plot…Preview
- (Program 4-2) Plot a line chart of date versus temperature by adding Label on X and Y axis, and adding a Title and Grids to the chart, given…Preview
- On providing a single list or array to the plot() function, can matplotlib generate values for both the x and y axis?Preview
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction
We have already seen how to organise and analyse data using Pandas and NumPy. But analysis alone is not always enough. When you look at a table of numbers, patterns can be hard to spot.
Plotting using Matplotlib
Matplotlib is a Python library used to create static, animated, and interactive 2D plots or figures. It is the standard tool for data visualisation in Python.
Customisation of Plots
2 QPyplot provides a wide range of functions to make charts more informative and readable. A basic plot shows data, but customisation — adding labels, a title, grid lines, or a legend — turns a raw graph…
+−Programs1 question
Marker
A marker is a symbol that represents a single data value on a chart. In a line plot, by default, only the line connecting the points is drawn.
Colour
The colour of a plotted line or marker is one of the simplest ways to make a chart more readable or to distinguish between multiple data series.
Linewidth and Line Style
The linewidth and linestyle properties let you control the thickness and visual pattern of a line in a Matplotlib chart.
The Pandas Plot Function (Pandas Visualisation)
The plot() method built into Pandas Series and DataFrame objects is a convenient shortcut. Before Pandas version 0.17.0, you had to import matplotlib.pyplot and call plt.plot() directly.
Plotting a Line chart
2 QA line chart (or line plot) is a graph that shows the frequency of data along a number line. It is used to display a continuous dataset — meaning data that flows without gaps, like measurements over t…
+−Activities1 question
Customising Line Plot
The real book's own 'Customising Line Plot' content is Program 4-5 above — the same MelaSales.csv chart styled with marker='', markersize=10, linewidth=3, linestyle='--', and plt.xticks(ticks, df.Day)…
Plotting Bar Chart
Bar charts are the go-to choice when you want to compare values across different categories. A line plot is great for showing trends over time, but it struggles to make clear comparisons between separ…
Customising Bar Chart
The real book's own 'Customising Bar Chart' content is Program 4-7 above — the same MelaSales.csv grouped bar chart styled with color=['red','yellow','purple'], edgecolor='Green', linewidth=2, linesty…
Plotting Histogram
2 QA histogram is a type of column chart where each column represents a range of values, not a single value. The height of each column shows how many data points fall into that particular range.
+−Programs1 question
Customising Histogram
The real book's own 'Customising Histogram' content is Program 4-9 above — the same Name/Height/Weight DataFrame styled with edgecolor='Green', linewidth=2, linestyle=':', fill=False, hatch='o'.
Using Open Data
2 QThe real book's own 'Using Open Data' content is Program 4-10 above — the data.gov.in 'Seasonal and Annual Min/Max Temperature Series — India (1901-2017)' dataset (MinMaxSeasonalIMD2017.csv), read wit…
+−Programs1 question
Plotting Scatter Chart
2 QA scatter chart is a two-dimensional method for visualising data. It uses dots to represent the values obtained for two different variables — one variable is plotted along the x-axis and the other alo…
+−Programs1 question
Customising Scatter chart
2 QThe real book's own 'Customising Scatter chart' content is Program 4-13 (discount vs. sales), sizing bubbles with size=discount10 and styling with color='red', marker='', edgecolor='blue', linewidth=3…
+−Programs1 question
Plotting Quartiles and Box plot
5 QWhen you have a large dataset — like the scores of thousands of students in a national exam — it's hard to see patterns just by looking at raw numbers.
+−Programs1 question
+−Think & Reflect1 question
+−Programs1 question
+−Think & Reflect1 question
Customising Box plot
The real book's own 'Customising Box plot' content is Program 4-15 above — df.plot(kind='box', title='Compare Resorts', color='red', vert=False).
Plotting Pie Chart
3 QA pie chart is a circular graph divided into sectors, where each sector represents a proportion of the total.
+−Programs1 question
+−Programs1 question
Customisation of pie chart
A pie chart shows proportions, but the default look is often too plain. The textbook shows you how to customise it by adding a shadow, exploding a slice, and rotating the chart for better readability.…
Summary
- A plot is a graphical representation of a data set, also known as a graph or chart, used to show the relationship between two or more variables.
Exercises
+−Show 16 questionsHide questions16 questions
- Q1What is the purpose of the Matplotlib library?Free
- Q2What are some of the major components of any graphs or plot?Free
- Q3Name the function which is used to save the plot.Free
- Q4Write short notes on different customisation options available with any plot.Preview
- Q5What is the purpose of a legend?Preview
- Q6Define Pandas visualisation.Preview
- Q7What is open data? Name any two websites from which we can download open data.Preview
- Q8Give an example of data comparison where we can use the scatter plot.Preview
- Q9Name the plot which displays the statistical summary.Preview
- Q10Note: Give appropriate title, set xlabel and ylabel while attempting the following questions. Plot the following data using a line plot: | D…Preview
- Q11Collect data about colleges in Delhi University or any other university of your choice and number of courses they run for Science, Commerce…Preview
- Q12Collect and store data related to the screen time of students in your class separately for boys and girls and present it using a boxplot.Preview
- Q13Explain the findings of the boxplot of Figure 4.18 by filling the following blanks: (a) The median for the five subjects is _____ , ______,…Preview
- Q14Collect the minimum and maximum temperature of your city for a month and present it using a histogram plot.Preview
- Q15Conduct a class census by preparing a questionnaire. The questionnaire should contain a minimum of five questions. Questions should relate t…Preview
- Q16Visit data.gov.in , search for the following in “catalogs” option of the website: • Final population Totals, India and states • State Wise l…Preview
Sample & Board Papers
Sample papers and previous-year board questions for this subject.