Matplotlib Tutorial | How to graph a Grouped Bar Chart (Code included)
HTML-код
- Опубликовано: 24 сен 2024
- In this Matplotlib for Pyhton exercise, I will be showing how to create a grouped bar graph using the matplotlib library in Python. (It has been a long time since I create a tutorial video for matplotlib, there are quiet many terms I don't even recall. I am might have to remake the tutorial again with the same content).
Points to take away
- We will learn how to add data label (data label annotation)
- We will learn how to insert custom labels for X and Y axis.
- We will learn how to insert a legned
Source Code:
learndataanaly...
About Matplotlib:
Matplotlib is a Python data visualization library with a rich selection of charting. Although not the easiest Python library to master, but once you get comfortable using the library, you can build any types of charting and visualization possible.
► Buy Me a Coffee? Your support is much appreciated!
-------------------------------------------------------------------------------------
☕ Paypal: www.paypal.me/...
☕ Venmo: @Jie-Jenn
💸 Join Robinhood with my link and we'll both get a free stock: join.robinhood...
► Support my channel so I can continue making free contents
---------------------------------------------------------------------------------------------------------------
🌳 Becoming a Patreon supporter: / jiejenn
🛒 By shopping on Amazon → amzn.to/2JkGeMD
🗓 Get updated on new Python videos → / madeinpython
📘 More tutorial videos on my website → LearnDataAnaly...
📺 Also check out my 2nd channel Excel channel focus on sharing Excel tips: bit.ly/3B1DjSA
✉ Business Inquiring: RUclips@LearnDataAnalysis.org
#Matplotlib #Python
imp_stats = ['wins','losses']
df.groupby('Ability')[imp_stats].mean().plot(kind='bar',figsize=(10,6))
plt.xlabel('Abilites')
plt.ylabel('Total')
plt.title('Wins and Looses according to Prestige')
can this be also considered as the right way?
How about if i want to add the 3rd bar? should i just add something = ax.bar(indx + bar_width/2, something, bar_width, label='something') ? like the 2nd one?
Holy.... Thank you soooo soooo soooo soooo much My graph looks amazing :)
Fantastic! Thank you very much!
you are genius this was very useful thank youuuuu
hi, so after groupby we have a new dataframe named dataset. How do i retrieve data about all variables in the first column ? I tried something like col1 = dataset['gender'] but it return error, while dataset['math score'] works.
Edit: nvm found it, just add .reset_index() when grouping
how do i plot for example in your case math score against reading score against writing score
very useful. can you also let us know how do we remove the top, right and left frames in th graph?
Do you mean the borders on the outsid
@@jiejenn Yes
Thank you very much!!!!!!!!!!!!!!
how to group 3charts in the same manner without overlapping on one another
Very good. Thank you
Glad my video helped.
groups you do by columns. how could you separate the values if they are in single column?
for example: column GENER and the values are [female, male, bisexual, lgtbi]
Then you will need to separate the values from a single column.
how did you count the number of male and female alone without the score just the count
use groupby and size()
"Error tokenizing data. C error: Expected 1 fields in line 4, saw 2" What does it mean? i did same stuff as you...
The line 4 is: df = pd.read_csv("StudentsPerformance.csv")
Looks like there is an invisible line break somewhere in your script. Not sure I can help you in that case.
I managed to plot the graphs by modifying your code to fit my data set. However the legend cannot be created due to "No handles with labels found to put in legend". =(