Matplotlib
Matplotlib
WITH
MATPLOTLIB
PRESENTED BY:
D . VARUN(20EG112122)
CONTENTS
➢ INTRODUCTION
➢ SIMPLE LINE PLOT
➢ SIMPLE SCATTER PLOT
➢ VISUALIZING ERRORS
➢ DENSITY AND CONTOUR PLOTS
➢ HISTOGRAMS,BINNINGS AND DENSITY
➢ CUSTOMIZING PLOT LEGENDS
➢ CUSTOMIZING COLORBARS
INTRODUCTION
Data visualization which is the process of translating the numbers, text, or large
data sets into various types of graphs such as histograms, maps, bar plots, pie charts, etc.
For visualizations, we need some tools or technology. Matplotlib is one of the most
powerful libraries in python for data visualization. It is able to create different types of
visualization reports like line plots, scatter plots, histograms, bar charts, pie charts, box
plots, and many more different plots. This library also supports 3-dimensional plotting.
SIMPLE LINE PLOT
First import matplotlib.pyplot library for plotting functions. Also,
import the Numpy library as per requirement. Then define data
values x and y.
Multiple charts
We can display more than one chart in the same container by
using pyplot.figure() function. This will help us in comparing the
different charts and also control the look and feel of charts.
SIMPLE SCATTER PLOT
Scatter plots are used to observe relationship between variables and uses dots to represent the relationship
between them. The scatter() method in the matplotlib library is used to draw a scatter plot. Scatter plots are
widely used to represent relation among variables and how change in one affects the other.
VISUALIZING ERRORS
Errorbar graph
Error bars function used as graphical enhancement that visualizes the variability of the plotted data on
a Cartesian graph. Error bars can be applied to graphs to provide an additional layer of detail on the
presented data. As you can see in below graphs.
Error bars help you indicate estimated error or uncertainty to give a general sense of how precise a
measurement is this is done through the use of markers drawn over the original graph and its data
points. To visualize this information error bars work by drawing lines that extend from the center of
the plotted data point or edge with bar charts the length of an error bar helps to reveal uncertainty of
a data point as shown in the below graph. A short error bar shows that values are concentrated
signaling that the plotted averaged value is more likely while a long error bar would indicate that the
values are more spread out and less reliable. also depending on the type of data. the length of each
pair of error bars tends to be of equal length on both sides, however, if the data is skewed then the
lengths on each side would be unbalanced.
Adding Some error in y value
Adding Some error in x value
Adding error in x & y
Adding variable error in x and y
DENSITY AND CONTOUR PLOTS
Density Plots - In a density plot, the color of an area reflects how many events are in that
position of the plot. Density plots may also be formatted to base the color gradient to the values
of a different parameters.
Contour Plots - In a contour plot, the color and distribution of lines on the plot reflects how
many events are in that position, much like a topographical map. Contour plots may also be
formatted to display multiple files or populations on a single plot using Overlays.
HISTOGRAMS,BINNINGS AND DENSITY
➢ Two-dimensional Binnings:
To plot a two-dimensional histogram is to use Matplotlib's plt.hist2d function:
➢ Hexagonal Binnings:
Matplotlib provides the plt.hexbin to represents a two-dimensional dataset binned within
a grid of hexagons:
CUSTOMIZING PLOT LEGENDS
Plot legends give meaning to a visualization, assigning meaning to the various
plot elements. The simplest legend can be created with
the plt.legend() command, which automatically creates a legend for any
labeled plot elements:
MULTIPLE LEGENDS
We can work around this by creating a new legend artist from scratch, and then using the lower-
level ax.add_artist() method to manually add the second artist to the plot:
CUSTOMIZING COLORBARS
In Matplotlib, a colorbar is a separate axes that can provide a key for the
meaning of colors in a plot. The simplest colorbar can be created with
the plt.colorbar function.
DISCRETE COLOR BARS
Colormaps are by default continuous, but sometimes you'd like to represent discrete values. The
easiest way to do this is to use the plt.cm.get_cmap() function.
THANK YOU