Data Visualisation PyPlot
Data Visualisation PyPlot
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Bar Chart: A graph drawn using rectangular bars to
show how large each value is. The bars can be
horizontal or vertical. A bar graph makes it easy to
compare data between different groups at a glance.
Bar graph represents categories on one axis and a
discrete value in the other. With PyPlot, a bar graph
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Specifying Plot Size and Grid: To set up the size of
the graph/plot, we need to set up figure size as:
<matplotlib.pyplot>.figure(figsize=(<width>,<length
>))
e.g., import matplotlib.pyplot as plt
plt.figure(figsize=(5,7)) # 5 units is the width or
x-coordinate and 7 units is the height or y-
coordinate
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Changing Marker Type, Size and Color:
To change marker type, its size and color additional
arguments in plot() function is to be given as:
marker=<valid marker type>, markersize=<in
points>, markeredgecolor=<valid color>
There are various types of marker(‘.’, ’x’, ‘o’, ‘+’, ‘d’,
‘D’ etc.). If marker type is not specified, then data
points will not be marked on the line chart.
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Note: Make sure to set the limits keeping in mind
the data set being plotted. The data that falls into
the limits of X and Y-axes will be plotted. Rest of the
data will not show in the plot. Example:
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
Adding Legends SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Saving a Figure
To save a plot created using pyplot functions for
later use, savefig() is to be used. Figures can be
saved in different formats like .pdf, .png, .eps etc.
Syntax:
<matplotlib.pyplot>.savefig(<string with filename
and path>)
While specifying path, use double slashes to
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
Histogram using hist() function
The hist() of PyPlot module lets you create and plot
histogram from a given sequence(s) of numbers. The
syntax for hist() function is:
matplotlib.pyplot.hist(x, bins = None, cumulative =
False, histtype = ‘bar’, align = ‘mid’, orientation =
‘vertical’)
Parameters:
x : (n,) array or sequence of (n,) arrays
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
cumulative : bool, optional
If True, then a histogram is computed where each bin gives
the counts in that bin plus all bins for smaller values. The last
bin gives the total number of datapoints.
histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
SASWATI SARANGI
SASWATI SARANGI
orientation : {'horizontal', 'vertical'}, optional
If 'horizontal', barh will be used for bar-type histograms.
rwidth : scalar or None, optional
The relative width of the bars as a fraction of the bin
width. If None, automatically compute the width.
Ignored if histtype is 'step' or 'stepfilled’.
You can add color and label when you have multiple
datasets to be represented.
SASWATI SARANGI
Default is None
Values on Y-axis
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
A scatter plot is similar to plot() function if we
specify the line color and marker style string(e.g.,’r+’,
’bo’ etc.) without linestyle argument. The primary
difference between scatter() and plot() is that in
scatter plots, the properties of each individual
point(size, face color, edge color etc.) can be
individually controlled or mapped to data.
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI
SASWATI SARANGI SASWATI SARANGI
SASWATI SARANGI