19_Matplotlib
19_Matplotlib
x=[1,2,3,4]
y=[10,20,30,40]
plt.plot(x,y)
plt.show()
Bar Chart
• Shows the relationship between a numerical variable and a
categorical variable.
• For example, you can display the height of several individuals
using bar chart.
• Bar charts are used to present categorical data with rectangular
bars.
• The bars can be plotted vertically or horizontally, and their
heights/lengths are proportional to the values that they represent.
Use the bar() method to draw a bar plot diagram.
Bar plot
from matplotlib import pyplot as plt
Subject=["Mathematics","Physics", “Chemistry","Biology"]
Marks = [90,70,75,85]
plt.bar(Subject,Marks)
plt.show()
Histogram
• An accurate graphical representation of the distribution of numerical
data.
• It takes as input one numerical variable only.
• The variable is cut into several bins, and the number of observation per
bin is represented by the height of the bar.
• It is a type of bar plot where X-axis represents the bin ranges while Y-
axis gives information about frequency.
• The data points in a pie chart are shown as a percentage of the whole
pie.
• The area of the wedge is determined by the length of the arc of the
wedge.
• The extreme lines shows the highest and lowest value excluding
outliers.
• This type of plot is useful when you want to show the total
magnitude across different categories and the contribution of
each sub-category to that total.
Stacked bar plot
import matplotlib.pyplot as plt
categories = ['Category A', 'Category B', 'Category C']
values1 = [10, 15, 20]
values2 = [5, 10, 15]
plt.bar(categories, values1, label='Value 1')
plt.bar(categories, values2, bottom=values1, label='Value 2')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Stacked Bar Plot')
plt.legend()
plt.show()
Group Bar plot
• Also known as a clustered bar chart, is a type of bar chart that
displays multiple bars for each category side by side, rather than
stacking them on top of each other.