RUVIDEO
Поделитесь видео 🙏

Bar Charts Matplotlib || Lesson 3.1 || Python for Data Science || Learning Monkey ||

📁 Обучение 👁️ 16 📅 02.12.2023

Bar Charts Matplotlib
In this class, We discuss Bar Charts Matplotlib.
The reader should have prior knowledge of groupby and multi-index in the data frame. Click here.
The data set we considered in this class is discussed in our previous class.
Based on the assumption reader is aware of the data and multi-index in the data frame. We explain about bar charts.
Bar Charts
A Bar Chart consists of rectangular boxes that help to visualize the categorical data.
Take an example and understand how to construct bar charts in python matplotlib.
Example: Construct a bar chart for the region-wise total sale.
First, we have to use the groupby method and identify region-wise total sales in our sample store data.
The discussion about the data set and groupby method is made in our previous classes.
We do groupby on region and take the total sale.
The module matplotlib. pyplot contains all the methods to construct graphs. Click here.
The figure method is used to construct a figure.
The arguments 18,5 are the size of the figure. We can change the size of the figure based on the requirement.
To construct a bar chart, we use the method bar.
The bar method parameters are x-axis values and y-axis values.
The x-axis is a region in our example. We took the region values in a variable x.
The y axis is a total sale in our example. We took total sales in a variable y.
The parameter color is used to mention the color of the bar.
Bar width can be changed using the width parameter.
import pandas as pd
df=pd.read_excel('sampledata.xls',sheet_name='Orders')
print(df.head())

# Taking the sum of the sale group wise
temp=pd.DataFrame(df.groupby(['Region'])['Sales'].agg('sum'))
print(temp)
x=temp.index
y=temp['Sales'].values
print(x)

import matplotlib.pyplot as plt
z=plt.figure(figsize=(18,5))
plt.bar(x, y, color ='blue',width = 0.4)
plt.show()

xlabel ylabel and title Methods
The bar chart shown above does not have labels and titles.
Without labels and titles, we get confusion.
To add labels and titles, we use the methods xlabel, ylabel, and title.
The example code is given below.
import matplotlib.pyplot as plt
z=plt.figure(figsize=(18,5))
plt.bar(x, y, color ='blue',width = 0.2)
plt.xlabel("Region")
plt.ylabel("Sum of sale")
plt.title("Region Wise Total Sale")
plt.show()
Horizontal Bar Chart
The above bar charts we call vertical bar charts.
We can generate the horizontal bar charts by using the method barh.
The remaining parameters we discussed above are the same for the method barh.
# Horizontal Bar chart
import matplotlib.pyplot as plt
z=plt.figure(figsize=(18,5))
plt.barh(x, y, color ='blue')
plt.xlabel("sum of sale")
plt.ylabel("Region")
plt.title("Region Wise Total Sale")
plt.show()

Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists


Link for our website: https://learningmonkey.in

Follow us on Facebook @ https://www.facebook.com/learningmonkey

Follow us on Instagram @ https://www.instagram.com/learningmonkey1/

Follow us on Twitter @ https://twitter.com/_learningmonkey

Mail us @ [email protected]

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Bar Charts Matplotlib || Lesson 3.1 || Python for Data Science || Learning Monkey ||», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.