EXP7
EXP7
EXPERIMENT NO. 7
Data Visualization: Matplotlib and Seaborn Library.
Aim: 1. Write a program in python to explore the matplotlib and seaborn library.
2. Write a program to plot, subplot functions, change the color, line style of the plot.
3. Write a program to visualize data using scatterplot, boxplot, histogram, line graph,
bar chart, violin plot, and regression plot and to draw appropriate conclusions.
Theory:
Matplotlib is a comprehensive library for creating static, animated, and interactive
visualizations in Python. Matplotlib is an amazing visualization library in Python for 2D plots
of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and
designed to work with the broader SciPy stack. It can be used in python scripts, shell, web
application, and other graphical user interface toolkit. Matplotlib comes with a wide variety of
plots which helps to understand trends, patterns, and to make correlations. A procedural
interface is provided by the companion pyplot module, which may be imported directly.
Matplotlib.pyplot is a collection of functions. Each pyplot function makes some change to a
figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting
area, decorates the plot with labels, etc. While working with matplotlib.pyplot, some states are
stored across function calls so that it keeps track of the things like current figure and plotting
area, and these plotting functions are directed to the current axes. The pyplot module provide
the plot() function which is frequently use to plot a graph. Pyplot have the concept of the
current figure and the current axes. All plotting functions apply to the current axes.
Figure: It is a whole figure which may hold one or more axes (plots). We can think of a Figure
as a canvas that holds plots.
Axes: A Figure can contain several Axes. It consists of two or three (in the case of 3D) Axis
objects. Each Axes is comprised of a title, an x-label, and a y-label.
Axis: Axises are the number of line like objects and responsible for generating the graph limits.
Seaborn is a library for making statistical graphics in Python. It builds on top of matplotlib and
integrates closely with pandas data structures. Seaborn helps to explore and understand the
data. Its plotting functions operate on data frames and arrays containing whole datasets and
internally perform the necessary semantic mapping and statistical aggregation to produce
informative plots. Seaborn offers the following functionalities:
1. Dataset oriented API to determine the relationship between variables.
2. Automatic estimation and plotting of linear regression plots.
3. It supports high-level abstractions for multi-plot grids.
4. Visualizing univariate and bivariate distribution.
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Seaborn supports several different dataset formats, and most functions accept data represented
with objects from the pandas or numpy libraries as well as built-in Python types like lists and
dictionaries. Most plotting functions in seaborn are oriented towards vectors of data. When
plotting x against y, each variable should be a vector. Seaborn accepts data sets that have more
than one vector organized in some tabular fashion. There is a fundamental distinction between
“long-form” and “wide-form” data tables, and seaborn will treat each differently. A long-form
data table has the following characteristics: Each variable is a column and Each observation is
a row. For wide-form data, there is a clear association between the dimensions of the table and
the variable in the dataset, seaborn is able to assign those variables roles in the plot. For simple
datasets, it is often more intuitive to think about data the way it might be viewed in a
spreadsheet, where the columns and rows contain levels of different variables.
Code&Output:
Using matplotlib:
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Using seabornlib:
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab
SIES Graduate School of Technology
Sri Chandrasekarendra Saraswati Vidyapuram
Sector V, Nerul, Navi Mumbai - 400706
Conclusion:
Department of Artificial Intelligence and Data Science CSL601: Data Analytics and Visualization Lab