Unit 4 Data Visualization using Matplotlib - Copy
Unit 4 Data Visualization using Matplotlib - Copy
Unit 4
Data Visualization
using Matplotlib
Data Visualization using Matplotlib
Disclaimer
The content is curated from online/offline resources and used for educational purpose only
Data Visualization using Matplotlib
Learning Objectives
• Introduction to Matplotlib
• Matplotlib Installation
• Data Visualization
• Plotting and Visualization
• Figures and Subplot
• Colours, marker, and Line Style
• Text Annotation
• Three-Dimensional Plotting
• Logarithmic Axes in Matplotlib
Data Visualization using Matplotlib
Introduction to Matplotlib
• Matplotlib is a free and open-source drawing library that can work with a variety of drawing formats.
• You can generate plots, histograms, bar charts, and other types of charts with just a few lines of code.
• Matplotlib is an excellent Python visualization library for two-dimensional array plots.
Data Visualization using Matplotlib
Installing Matplotlib
Install Matplotlib in the command prompt terminal by running the following command:
Families of Visualizations
plt.subplot(1, 2, 1)
#the figure has 1 row, 2 columns, and this plot is the first plot.
plt.subplot(1, 2, 2)
#the figure has 1 row, 2 columns, and this plot is the second plot.
Data Visualization using Matplotlib
Line Plot
• Python line plots can be made using the pyplot library from Matplotlib.
• Load Matplotlib first in order to create a line plot. Importing the pyplot library from Matplotlib as plt is
standard procedure.
• The plt alias will be recognizable to other Python programmers.
Data Visualization using Matplotlib
Bar Charts
• To create a bar plot with Matplotlib, first import the pyplot library.
• The alias plt is frequently used to replace matplotlib.pyplot.
Data Visualization using Matplotlib
Scatter Plots
• To create scatter plots of (x,y) point pairs, use the scatter() method of the Matplotlib library.
• For scatter(), two lists or arrays must be provided as positional arguments.
• The x-value of each scatter plot point is specified by the first positional argument.
• The y-value of each scatter plot point is specified by the second positional argument.
Data Visualization using Matplotlib
Legends in the graph are very similar to that we have our name on the mark sheet so whatever is written
there in the marksheet is basically mine similar to that whenever we define any plot we have to put some
legends for specifying data on an axis
Data Visualization using Matplotlib
Label
Data Visualization using Matplotlib
Ticks
• The values used to display particular points on the coordinate axis are called ticks.
• It might be a string or a number. The axes automatically adjust and take the default ticks whenever we
plot a graph.
• The default ticks provided by Matplotlib are generally adequate in common scenarios, but they are not
ideal for every plot.
Data Visualization using Matplotlib
Binning
• Binning is the process of dividing the data into these bins. When you create a histogram, you specify the
number of bins you want to use, or sometimes the bin edges are automatically determined based on the
data range and distribution
Data Visualization using Matplotlib
• They help convey insights, highlight key points, and make visualizations more understandable and
interpretable for viewers.
Data Visualization using Matplotlib
Pie Chart
• A pie chart is a circular data visualization that represents data as slices of a pie. Each slice
corresponds to a specific category or data group, and the size of the slice is proportional to the value
it represents.
Data Visualization using Matplotlib
plt.plot(data)
Data Visualization using Matplotlib
plt.plot(data)
Data Visualization using Matplotlib
plt.plot(datax,datay)
Data Visualization using Matplotlib
Summary
In this session we have learned -
• Data visualization with Matplotlib, a versatile and powerful Python library.
• Matplotlib showcases its ability to create stunning and customizable charts, plots, and graphs.
• From basic line plots to complex 3D visualizations, Matplotlib empowers users to convey insights from
data effectively.
• Discover its intuitive interface, rich customization options, and seamless integration with other data
manipulation libraries.
• We need to Unleash the potential of Matplotlib to transform raw data into compelling visual narratives
that aid analysis and decision-making.
Data Visualization using Matplotlib
Quiz
1. What is the purpose of Matplotlib’s pyplot module?
Quiz
2. Which of the following is not a type of Matplotlib plot?
a) Line plot
b) Scatter plot
c) Pie chart
d) Bar chart
Quiz
3. How can you add a title to a Matplotlib plot?
Quiz
4. What is the default color for Matplotlib plots?
a) Red
b) Blue
c) Green
d) Black
Answer: b) Blue
Data Visualization using Matplotlib
Quiz
5. What is the purpose of the legend() function in Matplotlib?
HANDS ON...!
Data Visualization using Matplotlib
References
• https://www.tableau.com/learn/articles/data-visualization/glossary
• https://www.w3schools.com/python/matplotlib_markers.asp
• https://www.geeksforgeeks.org/matplotlib-pyplot-legend-in-python/
• https://jakevdp.github.io/PythonDataScienceHandbook/04.09-text-and-annotation.html
• https://www.geeksforgeeks.org/three-dimensional-plotting-in-python-using-matplotlib/
• https://www.tutorialspoint.com/numpy/numpy_matplotlib.htm
Data Visualization using Matplotlib
Thank you...!