Class 12 Informatics Project
Class 12 Informatics Project
Class 12 Informatics Project
1 Introduction
Data Visualisation refers to the graphical or visual representation of information and data us-
ing visual elements like charts, graphs, maps, etc.
1.0.2 PLOT
A Plot is graphical technique for representing a data set, usually as a graph showing the relation-
ship between two or more variables. Lets look at an example
[3]: #Step 1: Import the Module
from matplotlib import pyplot as plt
plt.plot(x,y)
1
#Step 6: Saving a Graph/Plot
plt.savefig('Line1.png') # png, jpeg, pdf, svg
2
4. Provide the necessary Details for the Graph (Ex. Title, XLabel, YLabel, XTicks, YTicks, Show
Legend, etc)
5. [Optional - When Required] Save the Plot
6. Display the Plot
3
[59]: #Step 1: Import the Modules
from matplotlib import pyplot as plt
4
plt.show()
players = ['Dhoni','Virat','Shikhar','Rishabh']
runs = [76,102,48,27]
#Step 4:
plt.title("Player Runs")
plt.xlabel('Players')
plt.ylabel('Runs')
#Step 5
plt.show()
5
#Assignment: Create the following Bar Graph
[2]: from matplotlib import pyplot as plt
seasons = ['Summer','Monsoon','Autumn','Winter','Spring']
ice_cream = [100,80,70,45,85]
plt.show()
6
[1]: from matplotlib import pyplot as plt
plt.bar?
[1;31mSignature:[0m
[0mplt[0m[1;33m.[0m[0mbar[0m[1;33m([0m[1;33m
[0m [0mx[0m[1;33m,[0m[1;33m
[0m [0mheight[0m[1;33m,[0m[1;33m
[0m [0mwidth[0m[1;33m=[0m[1;36m0.8[0m[1;33m,[0m[1;33m
[0m [0mbottom[0m[1;33m=[0m[1;32mNone[0m[1;33m,[0m[1;33m
[0m [1;33m*[0m[1;33m,[0m[1;33m
[0m [0malign[0m[1;33m=[0m[1;34m'center'[0m[1;33m,[0m[1;33m
[0m [0mdata[0m[1;33m=[0m[1;32mNone[0m[1;33m,[0m[1;33m
[0m [1;33m**[0m[0mkwargs[0m[1;33m,[0m[1;33m
[0m[1;33m)[0m[1;33m[0m[1;33m[0m[0m
[1;31mDocstring:[0m
Make a bar plot.
The bars are positioned at *x* with the given *align*\ment. Their
dimensions are given by *height* and *width*. The vertical baseline
is *bottom* (default 0).
Many parameters can take either a single value applying to all bars
or a sequence of values, one for each bar.
7
Parameters
----------
x : float or array-like
The x coordinates of the bars. See also *align* for the
alignment of the bars to the coordinates.
To align the bars on the right edge pass a negative *width* and
``align='edge'``.
Returns
-------
`.BarContainer`
Container with all the bars and optionally errorbars.
Other Parameters
----------------
color : color or list of color, optional
The colors of the bar faces.
8
- scalar: symmetric +/- values for all bars
- shape(N,): symmetric +/- values for each bar
- shape(2, N): Separate - and + values for each bar. First row
contains the lower errors, the second row contains the upper
errors.
- *None*: No errorbar. (Default)
See :doc:`/gallery/statistics/errorbar_features`
for an example on the usage of ``xerr`` and ``yerr``.
Properties:
agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and ret
alpha: scalar or None
animated: bool
antialiased or aa: unknown
capstyle: `.CapStyle` or {'butt', 'projecting', 'round'}
clip_box: `.Bbox`
clip_on: bool
clip_path: Patch or (Path, Transform) or None
color: color
contains: unknown
edgecolor or ec: color or None or 'auto'
facecolor or fc: color or None
figure: `.Figure`
fill: bool
gid: str
hatch: {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
in_layout: bool
joinstyle: `.JoinStyle` or {'miter', 'round', 'bevel'}
label: object
linestyle or ls: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
9
linewidth or lw: float or None
path_effects: `.AbstractPathEffect`
picker: None or bool or float or callable
rasterized: bool
sketch_params: (scale: float, length: float, randomness: float)
snap: bool or None
transform: `.Transform`
url: str
visible: bool
zorder: float
See Also
--------
barh : Plot a horizontal bar plot.
Notes
-----
Stacked bars can be achieved by passing individual *bottom* values per
bar. See :doc:`/gallery/lines_bars_and_markers/bar_stacked`.
.. note::
In addition to the above described arguments, this function can take
a *data* keyword argument. If such a *data* argument is given,
every other argument can also be string ``s``, which is
interpreted as ``data[s]`` (unless this raises an exception).
10
plt.show()
1.3 HISTOGRAM
This graph is usually used to display the frequency of each item in the data. What is required for
such a representation is buckets/bins of the range (10-20,20-30,30-40. . . ) Bins can be mentioned in
either of two ways - A list [10,20,30,40,50,. . . ] - An integer depicting the no of bins required. The Bins
will then be generated by equally distributing the total range of the frequency data.
By Default the Bin has a integer value of 10. #### There are 2 techniques for getting Data for
Histogram. 1. Use the actual Frequency data as a list/array of values and use that to plot the
histogram. 2. Separate the Data and the Frequency of Occurance into 2 Lists and use both to plot
the histogram. Both techniques can be used depending on the requirement of the question.
SYNTAX
11
data = np.array([24,23,24,23,21,25,24,21,11,16,15,30,
31,34,35,35,34,31,32,35,13,21,34,21,
31,25,34,26,12,15,14,23,38,40,14,22,
27,39,24,29,29,27,24,34,35,27,32,39,34,34])
plt.hist(data, bins = 5, edgecolor = 'black')
plt.show()
data = np.array([24,23,24,23,21,25,24,21,11,16,15,30,
31,34,35,35,34,31,32,35,13,21,34,21,
31,25,34,26,12,15,14,23,38,40,14,22,
27,39,24,29,29,27,24,34,35,27,32,39,34,34])
plt.hist(data, bins = [10,15,20,25,30,35,40],edgecolor = 'black')
plt.show()
12
Histogram with Frequency Groups and Bins as Lists
[9]: from matplotlib import pyplot as plt
plt.show()
13
[11]: # Age 16, 17, 18, 19
from matplotlib import pyplot as plt
Age = [16,17,18,19]
Freq = [3, 18, 10, 4]
14
1.3.1 PRACTICE QUESTIONS
1. Plot a line graph to display growth in population in the past 7 decades. Use the following
Table Data for this purpose:-
2. Plot a line graph to show Sin Curve. (HOTS) Hint: Numpy has a function, numpy.sin() to find
the sin values.
3. Plot a line graph to show Cos Curve. (HOTS) Hint: Numpy has a function, numpy.cos() to find
the cos values.
4. Plot a Bar Graph to show the number of boys in each class 6- 12. Data should be imagined
by student.
15
5. Plot a Bar Graph for Marks scored in different subjects. Data should be imagined.
6. Plot a Histogram to find the number of employees coming to office between 7am to 12noon.
Use bins as 1 hr gaps.
16