Python Matplotlib

Published: 21 July 2024
on channel: Tech - Jroshan
878
like

#Python #Matplotlib For #DataVisualization

Plot Types Matplotlib supports various plot types:-✈️

❌ Line plots: plt.plot()

❌ Scatter plots: plt.scatter()

❌ Bar plots: plt.bar()

❌ Histograms: plt.hist()

❌ Box plots: plt.boxplot()

❌ Pie charts: plt.pie()

Here I have Share My experience to explain the different plot types supported by Matplotlib.

~~ Line plots (plt.plot())
Line plots are used to display data points connected by straight lines. They're ideal for showing trends over time or continuous data.

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.show()

~~ Scatter plots (plt.scatter())
Scatter plots display individual data points as markers on a 2D plane. They're useful for showing the relationship between two variables.
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.scatter(x, y)
plt.show()

~~Bar plots (plt.bar())
Bar plots use rectangular bars to represent data. They're commonly used to compare quantities across different categories.
categories = ['A', 'B', 'C', 'D']
values = [3, 7, 2, 5]
plt.bar(categories, values)
plt.show()

~~ Histograms (plt.hist())
Histograms represent the distribution of numerical data. They divide the data into bins and show the frequency of data points in each bin.
import numpy as np
data = np.random.randn(1000)
plt.hist(data, bins=30)
plt.show()

~~ Box plots (plt.boxplot())
Box plots, also known as box-and-whisker plots, display the distribution of data based on five summary statistics: minimum, first quartile, median, third quartile, and maximum.

data = [np.random.normal(0, std, 100) for std in range(1, 4)]
plt.boxplot(data)
plt.show()

~~ Pie charts (plt.pie()):
Pie charts represent data as slices of a circular graph, where each slice's size corresponds to its proportion of the whole.
sizes = [35, 30, 20, 15]
labels = ['A', 'B', 'C', 'D']
plt.pie(sizes, labels=labels)
plt.show()


On this page of the site you can watch the video online Python Matplotlib with a duration of hours minute second in good quality, which was uploaded by the user Tech - Jroshan 21 July 2024, share the link with friends and acquaintances, this video has already been watched 878 times on youtube and it was liked by like viewers. Enjoy your viewing!