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()
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.
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()
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()
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
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!
Thanks sir for this beautiful session...
Your welcome!
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:)
very nicely explained all , thanks
Hope that helped. Keep watching
spot on tutorial thank u
Glad it helped
Thank you.
Glad you liked it
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()
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()
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
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
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