0% found this document useful (0 votes)
38 views

MATPLOTLIB

The document describes 10 different types of plots that can be created using the matplotlib library in Python: 1) Line Plot, 2) Bar Plot, 3) Histogram, 4) Scatter Plot, 5) Pie Chart, 6) Box Plot, 7) Horizontal Bar Plot, 8) Area Plot, 9) Stacked Bar Plot, and 10) Step Plot. Code examples are provided for each type of plot to demonstrate how to generate the plots using matplotlib.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

MATPLOTLIB

The document describes 10 different types of plots that can be created using the matplotlib library in Python: 1) Line Plot, 2) Bar Plot, 3) Histogram, 4) Scatter Plot, 5) Pie Chart, 6) Box Plot, 7) Horizontal Bar Plot, 8) Area Plot, 9) Stacked Bar Plot, and 10) Step Plot. Code examples are provided for each type of plot to demonstrate how to generate the plots using matplotlib.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

matplot

August 31, 2023

1 Line Plot:
[28]: import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 12, 8, 15, 7]
plt.plot(x, y, marker='o')
plt.title("Line Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

#output

1
2 Bar Plot:
[29]: categories = ['A', 'B', 'C', 'D']
values = [25, 40, 15, 30]
plt.bar(categories, values, color='skyblue')
plt.title("Bar Plot")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.show()

#output

2
3 Histogram:
[30]: data = [32, 45, 50, 28, 36, 42, 38, 25, 29, 52, 48, 60]
plt.hist(data, bins=5, color='lightblue', edgecolor='black')
plt.title("Histogram")
plt.xlabel("Values")
plt.ylabel("Frequency")
plt.show()

#output

4 Scatter Plot:
[31]: x = [3, 5, 7, 10, 12, 15]
y = [25, 40, 30, 50, 35, 60]
plt.scatter(x, y, color='red', marker='o')
plt.title("Scatter Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")

3
plt.show()

#output

5 Pie Chart:
[32]: labels = ['Apples', 'Bananas', 'Oranges', 'Grapes']
sizes = [30, 25, 20, 15]
plt.pie(sizes, labels=labels, autopct='%1.1f%%', colors=['gold',␣
↪'lightskyblue', 'lightcoral', 'lightgreen'])

plt.title("Pie Chart")
plt.show()

#output

4
6 Box Plot:
[40]: data = [45, 60, 75,300, 80,350, 90, 95, 100, 110, 120,250,200]
plt.boxplot(data,vert=False,)
plt.title("Box Plot")
plt.ylabel("Values")
plt.show()

#output

5
7 Barh Plot:
[41]: categories = ['A', 'B', 'C', 'D']
values = [25, 40, 15, 30]
plt.barh(categories, values, color='pink')
plt.title("Horizontal Bar Plot")
plt.xlabel("Values")
plt.ylabel("Categories")
plt.show()

#output

6
8 Area Plot:
[43]: days = [1, 2, 3, 4, 5]
temperature = [25, 28, 30, 26, 22]
plt.fill_between(days, temperature, color='yellow', alpha=0.6)
plt.title("Area Plot")
plt.xlabel("Days")
plt.ylabel("Temperature")
plt.show()

#output

7
9 Stacked Bar Plot:
[27]: categories = ['A', 'B', 'C', 'D']
values1 = [25, 40, 15, 30]
values2 = [15, 20, 30, 25]
plt.bar(categories, values1, color='green', label='Value 1')
plt.bar(categories, values2, bottom=values1, color='orange', label='Value 2')
plt.title("Stacked Bar Plot")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.legend()
plt.show()

#output

8
10 Step Plot:
[26]: time = [1, 2, 3, 4, 5]
stock_price = [100, 110, 105, 120, 130]
plt.step(time, stock_price, color='red', where='mid')
plt.title("Step Plot")
plt.xlabel("Time")
plt.ylabel("Stock Price")
plt.show()

#output

9
10

You might also like