Matplotlib Tutorial (Part 2): Bar Charts and Analyzing Data from CSVs

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • In this video, we will be learning how to create bar charts in Matplotlib.
    This video is sponsored by Brilliant. Go to brilliant.org/cms to sign up for free. Be one of the first 200 people to sign up with this link and get 20% off your premium subscription.
    In this Python Programming video, we will be learning how to create bar charts in Matplotlib. Bar charts are great for visualizing your data in a way where you can clearly see the total values for each category. We'll learn how to create basic bar charts, bar charts with side-by-side bars, and also horizontal bar charts. We will also learn how to load our data from a CSV file instead of having it directly in our script. Let's get started...
    The code from this video (with added logging) can be found at:
    bit.ly/Matplotlib-02
    CSV Tutorial - • Python Tutorial: CSV M...
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com/shop/coreyschafer
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Python #Matplotlib

Komentáře • 347

  • @Sharmapawan98
    @Sharmapawan98 Před 5 lety +322

    Who needs python docs when you have such an amazing teacher

  • @coreyms
    @coreyms  Před 5 lety +115

    I hope everyone finds this video helpful. The next video of the series will be posted tomorrow at the same time. The next video will cover how to create pie charts.
    I'd like to thank Brilliant for sponsoring this series. If you'd like to check them out then you can sign up with this link and get 20% off your premium subscription:
    brilliant.org/cms

    • @dhananjaykansal8097
      @dhananjaykansal8097 Před 5 lety

      As usual lovely!!!!!!!

    • @tamasasztalos7484
      @tamasasztalos7484 Před 4 lety

      It's a great tutorial; the only thing I was missing is to add total values on the top of each bar charts (can be trickier for stacked bar chart)

    • @ishanpand3y
      @ishanpand3y Před 4 lety

      Thank you, sir, for providing top-class tutorials for free.

    • @JuniorDIEKA
      @JuniorDIEKA Před 4 lety

      Hello Corey!
      Please can you advise:
      1. how did you the clean the data within the column " LanguageWorkedWith" so that you can generate this clear data?
      2. After I have split it and save it to another csv file a part from the main, the is the output: [(" 'JavaScript'", 53020), (" 'HTML/CSS'", 39761), (" 'Java'", 29863), ("['Bash/Shell/PowerShell'", 28340), (" 'SQL']", 28178), (" 'Python'", 26185), (" 'PHP'", 20394), (" 'SQL'", 19094), (" 'TypeScript']", 16091), ("['HTML/CSS'", 15322)]
      [Finished in 33.6s]
      3. According the below output , how will I do so that it can bring the sum exact of the occurrence of the languages as it look like not doing it?
      Thank you,

    • @JoshKonoff1
      @JoshKonoff1 Před 3 lety

      Where is the CSV for this? I don't see it in the description. Thank you!

  • @ishanpand3y
    @ishanpand3y Před 4 lety +73

    In case you don't know, the shortcut for 8:13 in jupyter notebook is *Ctrl + left mouse click* on the different lines one by one. You can write at different lines at the same time.

  • @MrBuion
    @MrBuion Před 4 lety +83

    These series is much better than the curses in Udemy I paid for. Thank you very much.

  • @bmwmhamam
    @bmwmhamam Před 4 lety +5

    No body teaches like you. You are the best. Amazing delivery of information, truly useful tutorials. Thank you so much.

  • @sunshadow9704
    @sunshadow9704 Před 2 lety +3

    Corey, you are great teacher. You have rare ability to explain calmly. Much appreciating your efforts.

  • @Ghasakable
    @Ghasakable Před 5 lety +15

    Man, you are awesome, everything I have learned about python started from your channel, I wish you the very best all success, as you make everyone happy, keep up the excellent work, we all heavily rely on you.

    • @coreyms
      @coreyms  Před 5 lety +5

      Thanks! That's very kind of you.

  • @lalu225
    @lalu225 Před 5 lety +5

    Excellent tutorial Corey! Real life stuff and practical, including the use of Counter. It's important to show these data preparation steps. Very helpful indeed, thank you.

  • @TheShubham67
    @TheShubham67 Před 4 lety +9

    This series with pandas one has taken my skills to a new level.

  • @KienDoanTrung168
    @KienDoanTrung168 Před 5 lety +5

    such a great Python instructor with an angelic voice. Thank you so much 😊

  • @abhishek_raj
    @abhishek_raj Před 3 lety +1

    Right from reading data from a csv file to plotting it, you helped a lot of people.

  • @apoorvwatsky
    @apoorvwatsky Před 5 lety +81

    23:40 here's that one liner if anybody's interested. Personally, I like this more.
    languages, popularity = map(list, zip(*language_counter.most_common(15)))

    • @costasvas341
      @costasvas341 Před 4 lety +1

      Really nice! Could you please explain what the "*" symbol does?

    • @paklong2556
      @paklong2556 Před 4 lety

      nice

    • @jg9193
      @jg9193 Před 4 lety

      Or just: list(zip(*language_counter.most_common(15))). Map is unnecessary as list() automatically maps over an Iterable

    • @corben3348
      @corben3348 Před 4 lety +3

      @@jg9193 but if you don't use map(list, iterable) then languages and popularity will be tuples so you cannot use reverve() for the rest of the tutorial. Or languages, popularity = [list(e) for e in zip(*language_counter.most_common(15))] without map

    • @jg9193
      @jg9193 Před 4 lety +2

      @@corben3348 Fair point, I didn't think of that. That said, he could just do languages[::-1] instead of languages.reverse() to reverse a tuple
      Then again, using list() would even be unnecessary if he did that

  • @storiesshubham4145
    @storiesshubham4145 Před 2 lety +1

    I can't express how amazing this video is. What a great teacher you are. 🔥🔥

  • @miosz952
    @miosz952 Před 4 lety +4

    The great thing about your tutorials is that despite main topic, you learn a lot useful tricks, modules etc.

  • @djadamkent
    @djadamkent Před 5 lety +14

    Another great video, thank-you. A Pandas series of videos would be awesome!

  • @ahmedskasmani
    @ahmedskasmani Před 4 lety +4

    Amazing content Corey. The way you simplify the material and explain is awesome, many thanks. Can you please also do a video showing your setup and how you make video's. Thanks !!!

  • @ItzSenaCrazy
    @ItzSenaCrazy Před 5 lety +3

    What I really like is your videos, Corey. I can learn Python and English ;D
    Thanks!!

  • @fangshizhu9383
    @fangshizhu9383 Před 3 lety +1

    At 8:12, when you selected multiple locations and simultaneously type the same code to multiple lines, my world just expanded!

  • @LashaGoch
    @LashaGoch Před 3 lety +1

    This is gold! Thank you very much for doing this, you have incredible talent to explain complicated stuff in an easy manner, keep up good work :)))

  • @rnytpl
    @rnytpl Před 3 lety

    Thank you man, appreciate the effort and time you've put in creating such amazing content as these.

  • @randiarisman2419
    @randiarisman2419 Před 4 lety

    Another great video form you, Corey. Thank you, you made my day everyday!!

  • @dgh25
    @dgh25 Před rokem

    Your videos are just sprinkled with little golden nuggets! I love it ❤

  • @redferne01
    @redferne01 Před 5 lety +3

    Thank you for your work. I enjoy every lesson.

  • @mohammedismail308
    @mohammedismail308 Před 5 lety

    Thanks a lot Corey. Really your videos are endless treasure.
    Just a way for plotting bar charts for more than one dataset on the same plot without need to numpy. Just use built-in map function.
    width = 0.25 #Width of bar
    plt.bar(list(map(lambda x: x-width/2, age_x)), salaries1, color = 'k', width = width)
    plt.bar(list(map(lambda x: x+width/2, age_x)), salaries2, color = 'r', width = width)

  • @androkranjcevic1988
    @androkranjcevic1988 Před 3 lety

    Really nice work over here, the most important man on youtube for me.

  • @shazkingdom1702
    @shazkingdom1702 Před 5 lety +2

    This is the best Corey; Thank you very much from my 🧠 and ❣

  • @58_yesilgul
    @58_yesilgul Před 6 měsíci

    What a perfect lesson, fast and insightful pieces of knowledge...

  • @dalanxd
    @dalanxd Před 3 lety

    Corey Schafer saves my life once again...
    Deep gratitude for your work, man!

  • @fourdaysdead
    @fourdaysdead Před 5 lety +1

    thank you very much, very clear and straight to the point!

  • @dhssb999
    @dhssb999 Před rokem

    best matplotlib tutorial ever!

  • @borhansiddiki7079
    @borhansiddiki7079 Před 4 lety +2

    I think your videos are more understandable than rest of the youtube channels

  • @introduction_official6547
    @introduction_official6547 Před 4 měsíci +1

    Very informative video, good job Mr Corey

  • @luiggitello8546
    @luiggitello8546 Před 7 měsíci

    This is the best content on CZcams, thank you for so much

  • @tongliu1076
    @tongliu1076 Před 4 lety

    Great video as always! Really helpful for detailed explanation.

  • @gamengine1176
    @gamengine1176 Před 4 lety

    Very helpful video. The pandas method is much simpler and easier to understand. Thanks Corey!

  • @pratikarai8115
    @pratikarai8115 Před 4 lety

    Your explanation is awesome...thank you so much ...A great teacher for a lifetime...

  • @dhairyaoza5422
    @dhairyaoza5422 Před 3 lety

    thank you so much sir,really glad i found ur playlist and didn't waste time on other platforms

  • @minghaotao6259
    @minghaotao6259 Před 5 lety +2

    Thank you for sharing your knowledge!

  • @brumarul7481
    @brumarul7481 Před 3 lety +1

    This is pure Gold .

  • @Linshark
    @Linshark Před 2 lety

    I just came across this series of videos. They are extremely good :-)

  • @alexanderten5497
    @alexanderten5497 Před 5 lety +2

    Thank you very much.its a great tutorial as always

  • @abhishek_raj
    @abhishek_raj Před 3 lety

    You explain things really well, kudos!

  • @giuseppeceravolo93
    @giuseppeceravolo93 Před 4 lety

    Thank you so much for your hard work! You are a great teacher and your video tutorial represent a valuable resource :)

  • @shadowmasked7188
    @shadowmasked7188 Před rokem +1

    Thank you very much bro, Greetings from Azerbaijan.

  • @thebuggser2752
    @thebuggser2752 Před 8 měsíci

    Another great video. Thanks!!

  • @akunnaemeka395
    @akunnaemeka395 Před 2 lety

    thank you Brilliant for supporting Corey

  • @lillyclive2641
    @lillyclive2641 Před 4 lety +1

    Such a great help, thankyou so much!

  • @Anon282828
    @Anon282828 Před 2 lety

    thank you for always showing the clear code before abbreviating

  • @PaoloCondo
    @PaoloCondo Před rokem

    Thank you for the series of video! :)

  • @muzaianghanem5644
    @muzaianghanem5644 Před 4 lety +1

    That's true......you are an amazing teacher. This was very helpful

  • @franklinlima2571
    @franklinlima2571 Před 4 lety +1

    Great video! Thank you man

  • @DidaKusAlex
    @DidaKusAlex Před 2 lety

    great tutorial! the best!! thanks for teaching us!

  • @akashdeepchauhan5
    @akashdeepchauhan5 Před 3 lety

    You're making machine learning interesting, thank you

  • @MagnusAnand
    @MagnusAnand Před 2 lety

    I can't believe we need this hack to make a bar chart.
    Great video.

  • @nicholasmaloof8378
    @nicholasmaloof8378 Před 5 lety +4

    2 weeks later and still not a single dislike on this video

  • @SandeepChaudhary-vx9zy
    @SandeepChaudhary-vx9zy Před 4 lety +1

    Great explanation...thanks a lot Corey sir

  • @DeepakKumar-uz4xy
    @DeepakKumar-uz4xy Před 5 lety +1

    thank you professor. love from india. u know what i dont like to read those documentation. when i saw your videos.

  • @shuklarahul17
    @shuklarahul17 Před 4 lety +1

    As you mentioned Zip can also be used
    language = cnt.most_common(10)
    language.reverse()
    language_X, language_Y = list(zip(*language))
    plt.barh(language_X, language_Y)

  • @emmanueljimawo5595
    @emmanueljimawo5595 Před 5 lety +1

    Great videos. I'm so grateful...

  • @Martin-ij2fp
    @Martin-ij2fp Před 3 lety

    Great video!

  • @Coney_island23
    @Coney_island23 Před 2 lety

    thank you!!!! you ar an excellent teacher

  • @ondereren5003
    @ondereren5003 Před 3 lety

    Amazing video !

  • @brucegwon
    @brucegwon Před 3 lety

    This is the best fantastic lecture for the relation of Python and Pandas I've ever seen!!!!!!!!!!!!!!
    Xie Xie!!!

  • @eliesawan9513
    @eliesawan9513 Před 3 lety +1

    you are amazing, waiting for your data science ( ML, AI ) course...... THANKS A LOT!

  • @edcoughlan5742
    @edcoughlan5742 Před 5 lety +5

    These videos are great! Coming from R (and ggplot) I was a tad skeptical that Python could emulate R when it came to data viz, but I stand corrected.

  • @luiscesar_agais
    @luiscesar_agais Před 2 lety

    Very nice your explanations. Congratulations.

  • @AbubakerMahmoudshangab

    Corey. Million thanks bro

  • @SahilKhan-rv9xb
    @SahilKhan-rv9xb Před 3 lety +9

    for those wondering how to obtain the CSV file, once you've clicked on it and you see all of the data in your web browser, just right click and say save as

  • @markkennedy9767
    @markkennedy9767 Před 8 měsíci

    Thanks for this. Great lesson. As you say, creating multiple bars seems extraordinarily hacky. I would have thought this would be easily dealt with by a plotting library

  • @cooldudesjce
    @cooldudesjce Před 4 lety

    Amazing Tutorials Thanks soo much !

  • @rahil1575
    @rahil1575 Před rokem

    you are a life saviour for people like me

  • @SM-vu6fm
    @SM-vu6fm Před 2 lety

    Counter() is the best thing I learned today

  • @frankconte2457
    @frankconte2457 Před 5 lety +3

    Another great tutorial. Thank you. However, using a Jupyter Notebook, I am having a problem with plt.bar, plt.barh. The error I receive is "unsupported operand type(s) for -: 'str' and 'float'.

  • @johnjones5659
    @johnjones5659 Před 4 lety

    Thanks you and Brilliant

  • @hayetchekired462
    @hayetchekired462 Před 3 lety

    great instructor

  • @mindbodysoulsculpt6479

    Great Matplotlib tutorial. But I feel like this is where Pandas also really comes to play, we can use sep = ; inside of the read_csv function instead of creating a custom function. Also, using iloc and loc for indexes and many more awesome built in functions

  • @ericfricke4512
    @ericfricke4512 Před 4 lety +2

    Programming is so fun.

  • @michaelren2821
    @michaelren2821 Před 3 lety

    great tutorial, thanks

  • @mallusreddy
    @mallusreddy Před 5 lety +1

    Thank you so much.. It's a great vedio....

  • @noway4715
    @noway4715 Před 4 lety

    Best of the best!

  • @eduardosiqueirabonfim98

    Thanks!

  • @oscarkiamba7690
    @oscarkiamba7690 Před rokem

    The best in you tube .👏

  • @KC-rl8ub
    @KC-rl8ub Před 5 lety +8

    hi Corey....god bless you

  • @Kralnor
    @Kralnor Před 2 lety

    Fantastic video. Exactly the type of content that I was looking for to create beautiful bar graphs.

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt Před 4 lety +1

    Great, amazing video

  • @nowyouknow2249
    @nowyouknow2249 Před 5 lety

    Wonderful!
    Thanks a lot CMS

    • @chrisray1567
      @chrisray1567 Před 5 lety

      collins anele That probably won’t work because value_counts() won’t split the data at the semicolons, so “Python;JavaScript” would be one value instead of two.

    • @nowyouknow2249
      @nowyouknow2249 Před 5 lety

      You are right. I just realised that.

  • @rotrose7531
    @rotrose7531 Před 2 lety

    Thank you very much. Please, please come back!

  • @kerimabdul2263
    @kerimabdul2263 Před 4 lety +1

    great video.

  • @abhinav9561
    @abhinav9561 Před 3 lety

    Thanks man!!

  • @gurukirans266
    @gurukirans266 Před 4 lety +1

    Tq sir
    This is for u sir
    while 2 < 3:
    print('thank you soo much')

  • @rahulp1985
    @rahulp1985 Před 3 lety +2

    How to have the percentage values also listed along the Y-axis with language names as shown in the plot in the stackoverflow website (towards the end of the video)

  • @harshman11
    @harshman11 Před 5 lety +1

    I love Corey's videos*(infinite).

  • @mamathakavety6529
    @mamathakavety6529 Před rokem +1

    Please do a tutorial on numpy as well, it would be super helpful, by the way awesome content😁

  • @karishmakaris7165
    @karishmakaris7165 Před 4 lety +1

    ty soo much .. yu are the best ..

  • @rajivswargiary1536
    @rajivswargiary1536 Před 5 lety +1

    Great tutorial sir

  • @jsceo
    @jsceo Před 5 lety +7

    that feel when I paused tutorial to figure out how to extract languages and popularity from language_counter and later it turns out that you've done that exactly in the same way, lol

  • @FerdinandCoding
    @FerdinandCoding Před 4 lety +1

    thank you for python tutorial

  • @gurukirans266
    @gurukirans266 Před 4 lety +1

    Thank you lot sir 😃

  • @tnz3116
    @tnz3116 Před 5 lety

    Excellent videos Corey. Thanks.Quick question
    I am getting an error at this line 'plt.barh(languages, popularity)' Error is: TypeError: unsupported operand type(s) for -: 'str' and 'float'
    Using Spyder 3.1.4 and Python 3.6.
    Downloaded the data.csv and copied it. Cannot figure out what's going on.

  • @sahibaalagh
    @sahibaalagh Před 4 lety +1

    Hello Corey! Instead of using x_indexes, I transformed ages_x into a numpy array and used that array in the plot function. It shows same resuts as x_indexes and moreover, I do not need to change the x-axis notations. However, I want to know, is this method correct?