Python Seaborn - 2 | Creating a COUNT PLOT or FREQUENCY PLOT to See the Frequency Distribution
Вставка
- Опубліковано 21 лип 2024
- Python Seaborn - 1 | Creating a COUNT PLOT or FREQUENCY PLOT or COLUMNER PLOT or BAR PLOT to See the Frequency Distribution of a Categorical Variable
This video covers:
00:00 - Introduction
01:00 - Importing Seaborn and other required libraries
01:43 - Importing excel data file
02:45 - Creating a basic COUNTPLOT to show the frequency/count of values in a given categorical variable
04:11 - Changing/Adjusting the figure size of a plot figure
05:53 - Horizontal count plot | Bar plot to show the count | Convert the count plot to horizontal bars
06:46 - Creating a count plot for two categorical variables | Adding hue to the count plot
08:26 - Changing the color of columns in count plot using color palette
09:49 - Changing the style of count plot i.e. changing face color, line width, edge color or line color
You can download the excel files used in this video using:
File Name : supermarket_sales.xlsx
URL : github.com/LEARNEREA/Python/t...
You can download the script created in this video using:
File Name : 2.Seaborn_CountPlot.py
URL : github.com/LEARNEREA/Python/t...
Seaborn Official website for count plot:
seaborn.pydata.org/generated/...
#python #pythonforbeginners #VisualizationInPython #seaborn #visualizationUsingSeaborn #CountPlotUsingSeaborn - Наука та технологія
To have numbers at bars/columns -
import seaborn as sns
import matplotlib.pyplot as plt
# load the iris dataset
iris = sns.load_dataset('iris')
# create a count plot of the species column
ax = sns.countplot(x='species', data=iris)
# add count values to the bars
for p in ax.patches:
ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.show()
Wow, this is exactly what I needed thank you for explaining it so well!
Glad it was helpful!
very nicely explained all , thanks
Hope that helped. Keep watching
Thanks sir for this beautiful session...
Your welcome!
spot on tutorial thank u
Glad it helped
Thank you.
Glad you liked it
Hello. Thank you for all the useful videos. On 2:05, when you want to read the excel file, you have this drop down menu of functions. Could you let me know how you added it to jupyter notebook? Thanks.
when you write "pd." just prcess Tab key from your keyboard and you will get that dropdown. Enjoy:)
hey thanks for the video.. if i want the actual number in each of the bars how do it get it
will make a video on this soon, in the meantime, you can use this for reference -
www.geeksforgeeks.org/how-to-show-values-on-seaborn-barplot/
Hey this tutorial is great, but I'm getting numbers on the labels for x-axis instead of column names on it. How do I fix this?
try below -
You may find it little lengthier, try the below -
import seaborn as sns
import matplotlib.pyplot as plt
# load the iris dataset
iris = sns.load_dataset('iris')
# create a count plot of the species column
ax = sns.countplot(x='species', data=iris)
# add count values to the bars
for p in ax.patches:
ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.show()
If there is number on x-axis and count on y axis , how to give range for x axis, how to change range on y axis like (5,10, 15)
Hi Uma,
try below -
sns.countplot(data=your_df,x="your_x_label_column")
plt.ylim(min_number_you_want_to_start_from,max_number_you_want_to_start_from)
for example, I have this data -
data = {"Gender":[1,3,2,3,1,2,3,2,1,3,1],
"Income":[80,34,40,45,50,90,70,60,45,40,85]}
and I want to ploat "Gender" on x axis and want see the count in range between 3 to 12 then this is waht I'll do
sns.countplot(data=df,x="Gender")
plt.ylim(3,12)
DO NOT FORGET TO IMPORT - import matplotlib.pyplot as plt
let me know if this helps or not
How would you add labels to the plot to indicate the actual number?
You may find it little lengthier, try the below -
import seaborn as sns
import matplotlib.pyplot as plt
# load the iris dataset
iris = sns.load_dataset('iris')
# create a count plot of the species column
ax = sns.countplot(x='species', data=iris)
# add count values to the bars
for p in ax.patches:
ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.show()
where is frequency distribution???countplot and fdist both are different right?
What sort of frequency you actually want see, if you can give an example, possibly I'll be able to suggest you a better solution
bro not getting suggestion on palette, producing error
Suggseted in the comment on barplot.. alternatively you can also use -
sns.color_palette
to get the list
me too now lol