Matplotlib Charts
Chapter 4
Introduction to Matplotlib
• - Matplotlib is a powerful Python library for
data visualization.
• - It is widely used for creating static, animated,
and interactive visualizations.
• - Installation: install matplotlib
• - Basic Import: import [Link] as plt
Line Charts
• - Used to display trends over time.
• - Useful for showing continuous data.
• - Example:
• [Link](x, y, marker='o', linestyle='-', color='b')
Line Chart Code Example
• import [Link] as plt
• x = [1, 2, 3, 4, 5]
• y = [10, 20, 25, 30, 40]
• [Link](x, y, marker='o', linestyle='-', color='b')
• [Link]('Days')
• [Link]('Revenue ($)')
• [Link]('Sales Over Time')
• [Link]()
Bar Charts
• Used to compare different categories.
• Useful for showing counts and distributions.
• Example:
• [Link](categories, values, color='blue')
Bar Chart Code Example
• categories = ['A', 'B', 'C', 'D']
• values = [10, 15, 7, 12]
• [Link](categories, values, color=['blue', 'red',
'green', 'purple'])
• [Link]('Categories')
• [Link]('Values')
• [Link]('Bar Chart Example')
• [Link]()
Scatter Plots
• Used to show relationships between two
variables.
• Great for correlation analysis.
• Example:
• [Link](x, y, c='red')
Scatter chart
• import [Link] as plt
• x = [1, 2, 3, 4, 5]
• y = [10, 20, 25, 30, 40]
• [Link](x,y,c='red')
• [Link]('Categories')
• [Link]('Values')
• [Link]('Scatter Chart Example')
• [Link]()
Pie Charts
• Used to show proportions of a whole.
• Best when displaying percentage distributions.
• Example:
• [Link](sizes, labels=labels, autopct='%1.1f%
%')
Pie Chart
• import [Link] as plt
• labels = ['Apples','Bananas','Dates','Mangoes']
• sizes = [30,25,25,20]
• colors = ['red','yellow','green','pink']
• [Link](sizes,labels=labels,colors=colors,autopc
t='%1.1f%%')
• [Link]('Fruit distribution')
• [Link]()
Histogram
• Used to visualize frequency distributions.
• Best for analyzing data spread.
• Example:
• [Link](data, bins=30, color='blue')
Box Plot
• Used to display summary statistics of data.
• Shows median, quartiles, and outliers.
• Example:
• [Link](data)
Interactive Plots
• Matplotlib allows interactive plots using
[Link]().
• Useful for live data visualization.
• Example:
• [Link]() and [Link](0.5)
Summary
• Recap of Matplotlib chart types.
• Best practices for effective visualization.
• Q&A session.