0% found this document useful (0 votes)
10 views4 pages

Study Material Visualization

The document provides an overview of data visualization using Python's matplotlib library, detailing the anatomy of charts, types of plots, and basic plotting functions. It explains key concepts such as axes, labels, legends, and customization options for various plot types including line, bar, and histogram. Additionally, it includes code examples for creating multiple plots and saving them in different formats.

Uploaded by

Harsh Amera
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)
10 views4 pages

Study Material Visualization

The document provides an overview of data visualization using Python's matplotlib library, detailing the anatomy of charts, types of plots, and basic plotting functions. It explains key concepts such as axes, labels, legends, and customization options for various plot types including line, bar, and histogram. Additionally, it includes code examples for creating multiple plots and saving them in different formats.

Uploaded by

Harsh Amera
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

Class XII Informatics Practices  Axes: The axes define the area (mostly

Study Material rectangular in shape for simple plots) on which


actual plot (line or bar or graph etc.) will appear.
Data Visualization-Python Unit-1 Axes have properties like label, limits and tick
Data Visualization (1 or 2 Marks) marks on them.
 Data visualization is the discipline of trying to There are two axes in a plot:
expose the data to understand it by placing it (i) X-axis the horizontal axis,
in a visual context. ii) Y – axis the vertical axis
 Its main goal is to distill large datasets into a) Axis Label: It defines the name for an axis. It is
visual graphics to allow for easy understanding individually defined for X– axis and Y–axis each.
of complex relationships within the data. b) Limits: These define the range of values and
number of values marked on X–axis and Y – axis.
Purpose of Data visualization (1 or 2 Marks) c) Tick_Marks: The tick marks are individual
 Better analysis point marked on the X – axis or Y – axis.
 Quick action Title: This is the text that appears on the top of
 Identifying patterns the plot. It defines what the chart is about.
 Finding errors Legends: These are different colors that identify
 Understanding the story different sets of data plotted on the plot. The
 Exploring business insights legends are shown in a corner of the plot. We use
legend as following types:
 Grasping the latest trends plotting library
[Link] (loc="upper left") or [Link]
(loc=2)
Anatomy of a Chart
To import the library for plotting (1 Mark)
import [Link] as pl
Basic steps to follow while plotting:
(a) Choose appropriate plot type and then the
function
• Line plot: plot ()
• Bar plot: bar () and barh()
• Histogram: hist ()
(b) Understand the data and assign the legend
values
 assign the axis labels
 assign plot title
Introduction to matplotlib (1 Mark)
 [Link] is a collection of functions for
Different color codes:
2D plotting.
 Some of the types of plots: Line, Bar,
Histogram, Pie and Boxplot.

Matplotlib – pyplot features (1 or 2 Marks)


 Drawing – plots can be drawn based on passed Line Plot: (3 Marks)
data through specific functions. A line plot/chart is a graph that shows the
 Customization – plots can be customized as frequency of data occurring along a number line.
per requirement after specifying it in the Eg.
arguments of the functions. Like color, style import [Link] as pl
(dashed, dotted), width; adding label, title, and x = [1, 2, 3, 4, 5]
legend in plots can be customized. y = [23, 41, 26, 10, 31]
 Saving – After drawing and customization [Link](x, y,'r', label = "Sales", linewidth = 4)
plots can be saved for future use. [Link] ("Test Plot", loc="right")
 Figure: Pyplot by default plots every chart into [Link] ("X - AXIS")
an area called Figure. A figure contains other [Link] ("Y - AXIS")
elements of the plot in it.
[Link] ()
[Link] ()

Multiple line plots (3 Marks) To change the line style


Eg. We can add following additional optional
import numpy as np argument in plot(): linestyle or ls = [‘solid’ |
import [Link] as plt ‘dashed’ | ‘dashdot’ | ‘dotted’]
year = [2014, 2015, 2016, 2017, 2018] import [Link] as plt
jnvpasspercentage = [90, 92, 94, 95, 97] x = [1,2,3,4,5,6] y = [2,4,1,5,2,6]
kvpasspercentage = [89, 91, 93, 95, 98] [Link](x, y, color='green', linestyle='dashed',
[Link] (year, jnvpasspercentage, color='g') linewidth = 3, marker='o', markerfacecolor='blue',
[Link] (year, kvpasspercentage, color='orange') markersize=12)
[Link] ('Year') # Setting x and y axis range
[Link] ('Pass percentage') [Link] (1,8)
[Link] ('JNV KV PASS % till 2018') [Link] (1,8)
[Link] () [Link] ('x - axis')
[Link] ('y - axis')
[Link] (‘some cool customizations!')
[Link] ()

Or
Eg.
year = [1960, 1970, 1980, 1990, 2000, 2010]
pop_pakistan = [44.91, 58.09, 78.07, 107.7, 138.5,
170.6]
pop_india = [449.48, 553.57, 696.783, 870.133,
1000.4, 1309.1] Bar Plot: (3 Marks)
[Link] (year, pop_pakistan, color='g‘, marker=‘s’, A graph drawn using rectangular bars to show
label=“Pakistan”) how large each value is. The bars can be horizontal
[Link] (year, pop_india, color='orange‘, or vertical.
marker=‘*’, label=“India”) Eg.
[Link] ('Countries') import [Link] as pl
[Link]('Population in million') x = ['English','Hindi','Maths','Science','SST']
[Link] ('Pakistan India Population till 2010') y = [34, 54, 41, 44, 37]
[Link] () [Link] (x, y, width =0.8, label= "Marks",
[Link] () color="brown”, edgecolor="black")
[Link] ("Marks of 5 subjects”, loc="right")
[Link] ("Subject")
[Link] ("Marks")
[Link] ()
[Link] ()
[Link] ()

Note: – use barh () for creating horizontal bar


graphs

Multiple Bar Plots (3 Marks)


Eg.
import [Link] as plt Histogram: (3 Marks)
from [Link] import date2num A histogram is a graphical representation which
import datetime organizes a group of data points into user-
x = [[Link] (2011, 1, 4, 0, 0), specified ranges.
[Link] (2011, 1, 5, 0, 0), histtype: [‘bar’, ‘barstacked’, ‘step’, ‘stepfilled’], It
[Link] (2011, 1, 6, 0, 0)] is optional by default is ‘bar’ orientation:
x = date2num(x) [‘vertical’, ’horizontal’]
y = [4, 9, 2] Eg.
z = [1, 2, 3] import [Link] as pl
k = [11, 12, 13] import numpy as np
ax = [Link] (111) math=
[Link](x-0.2, y, width=0.2, color='b', align='center') [12,23,45,56,57,67,72,83,65,22,87,53,12,90,78,
[Link](x, z, width=0.2, color='g', align='center') 83, 45, 75, 37,28]
[Link](x+0.2, k, width=0.2, color='r', x = [Link] (len(math))
align='center') freq, bin, patches = [Link] (math, bins=10,
ax.xaxis_date() edgecolor = "black", label = "Math marks")
[Link] () # frequency give the list of number of events in
each bin
# bin is the bin size taken for making 10 bins.
# Check the number of bins given in the exam and
accordingly give the bin size.
# patches are the individual rectangle object
[Link] ("Performance of students", loc="right")
[Link] ("Mark in Maths")
[Link] ("Number of students")
[Link] ()
[Link] ()
or
import [Link] as plt
import numpy as np
label = ['Anil', 'Vikas', 'Dharma', 'Mahen', 'Manish',
'Rajesh']
per = [94, 85, 45, 25, 50, 54]
index = [Link] (len(label))
clr=[‘r’, ’g’, ’b’, ’c’, ’k’, ’y’]
[Link] (index, per, color=clr)
[Link] ('Student Name', fontsize=5)
[Link] ('Percentage', fontsize=5)
[Link] (index, label, fontsize=5, rotation=30)
[Link] ('Percentage of Marks achieve by student
Class XII')
Or
Eg.
import [Link] as plt
ages=[2,5,70,40,30,45,50,45,43,40,44,60,7,13,57,1
8,90,77,32,21,20,40]
range = (0, 100)
bins = 10
[Link](ages, bins, range, color = 'green', histtype =
'bar', rwidth = 0.8)
[Link] ('age')
[Link] ('No. of people')
[Link] ('My histogram')
[Link] ()

or
y = [95, 42, 69, 11, 49, 32, 74, 62, 25, 32]
[Link](y)
[Link] ('Bins')
[Link] ('Frequency')
[Link] ()

Save Plot: (1 Mark)


To save any plot use function [Link]
("[Link]")
Here [Link] is the name of the file where plot is
saved. Eg.
[Link] ('line_plot.pdf')
[Link] ('line_plot.svg')
[Link] ('line_plot.png')
# Parameter for saving plots .e.g.
[Link] ('line_plot.jpg', dpi=300, quality=80,
optimize=True, progressive=True)

You might also like