0% found this document useful (0 votes)
11 views

Matplotlib

Matplotlib is a comprehensive Python library for creating static, animated, and interactive visualizations. It allows creating various types of charts like line plots, bar charts, histograms, pie charts. The document discusses different plot types and how to customize visual aspects like labels, legends, grids using Matplotlib.

Uploaded by

RAJESH V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Matplotlib

Matplotlib is a comprehensive Python library for creating static, animated, and interactive visualizations. It allows creating various types of charts like line plots, bar charts, histograms, pie charts. The document discusses different plot types and how to customize visual aspects like labels, legends, grids using Matplotlib.

Uploaded by

RAJESH V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Matplotlib

In Python
Matplotlib: Visualization with Python

Matplotlib is a comprehensive library for creating static, animated, and


interactive visualizations in Python (any kind of 2d charts). Matplotlib makes easy
things easy and hard things possible.
• Create publication quality plots.
• Make interactive figures that can zoom, pan, update.
• Customize visual style and layout.
• Export to many file formats.
• Embed in JupyterLab and Graphical User Interfaces.
• Use a rich array of third-party packages built on Matplotlib.
What is
the
maximum
and
minimum
temperatu
re in the
week?
#importing the library and invoking the
inline magic function for smoot rendering
#Variables and values that we use for plotting
#Basic plot function
Marker Size
There are different short word or letters or signs to represent
functions. This can be seen from this url:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.p
lot.html
Plotting multiple values in a single chart

#This chart has a


disadvantage. The
viewer does not
know which value
has the X-axis and
which value has Y-
axis
Axes labels, Legend and grid
# for Legend can be placed anywhere in the
chart with the loc function. It can be placed
upper right, lower left or any where. loc='best'
is used to locate it in the best possible place.

Legend
#invoking Grid Function
Bar Chart
# the Values are in strings and the
program will not read string values for
bar diagram. So first we need to make
this values into numerical values.

So we can change the ‘company’ values in to a list


of array, either using the List function or by using
the arrange function which we use in this chart.
#Here we change the string values into
an array names xpos using the arrange
function.
#Then when we plot the
values it arrives. But to x
values are in numerical
format. To change it into
company name we use the
codes in the nest slide.
# We use ‘xticks’ function to change the array
numerical values into the company names in the
company variable name

Legend
To plot Two different measures. (Revenue and
Profit)

• company=['RIL',’FLPKT','WIPRO','TCS']
• revenue=[170,96,109,147]
• profit=[100,42,74,112]
By this way we can understand the real revenue and the actual
profit of the company.
Here this chart is bit confusing.
An ordinary person cant
understand anything from
such a type of chart. To easily
understand the chant the
values should be brought side-
by-side. Using the codes in the
next slide.
#Here we reduce and add 0.2 from
revenue and profit respectively and
give equal with to both the variables

#This Chart is much


mor simpler to read
and understand
# To make the horizontal chart, we use
‘barh’ function and makes the ticks
function to ‘yticks’.
Histograms in Python
Histogram shows us the frequency of the data.
Six patients are normal

4 Patients are diabetic

2 Pre-diabetic
# by default number of bins is set to 10

# Only one
set of values
is enough for
histogram
# the labels are assigned

# the bins
numbers are
assigned based
on the need to
determine the
Diabetic, Pre-
diabetic and
Non-Diabetic
patients
#To draw the histogram for
2 datasets

# This chart is okay but has


no label, chart name,
legend to identify which
colour is men and women.
# the orientation
can be changed
using
‘orientation’
function.
PIE CHART
#shadow is given to give a shadow to the
pie chart.

#axis command is used to make


the pixels of the circle in the equal
distribution , which makes the pie
more appealing.
#’autopct’ function is for giving
the values in the pic chart. 1.1
represent the no. of decimal
points to be followed by the
percentage value.

# explode
function is to
bring a piece of pie
out.
# ‘startangle’ can be
used to rotate the
pie. It mentions at
what angle the first
value should start.

You might also like