How to Make Bar Charts in Python

Stone River eLearning
A free video tutorial from Stone River eLearning
500,000+ Happy Udemy Students
4.2 instructor rating • 279 courses • 606,090 students

Learn more from the full course

Become a Professional Python Programmer

Learn all the important skills Python programmers need to get all the best programming jobs

39:22:04 of on-demand video • Updated March 2019

  • Understand and implement basic Python code
  • Create and run a real-world Python program
  • Access and parse the web with Python
  • Manage a database and remote server
  • Run code via a VPS
  • Create a website with Python
  • Visualize multiple forms of both 2D and 3D graphs, like line graphs, scatter plots, bar charts, and more
  • Load data from files or from internet sources for data visualization.
  • Load data from files or from internet sources for data visualization
  • Customize graphs, modifying colors, lines, fonts, and more
  • Visualize Geographical data on maps
  • Input and output data from a variety of data types
  • Visualize,combine and manipulate dataset
  • Develop in the real world using Python Django
  • Create Django web applications to solve a multitude of problems or needs
English What is going on everybody welcome to part 5 of section 2 of our data visualization with Python in MAP plot limt tutorial series. In this part what we're going to be talking about is bar charts so bar charts a real simple graph type where you've got bars of data. So if you don't know at a bar chart as you're about to see one but chances are you already know what one is. So what we're going to go ahead and do is we only this X Y and really we can we can probably get away with using this exact data here we'll get rid of these labels we'll just probably rewrite those and just delete everything else. The legend we can keep I don't really see any problem with that. And yes so let's go ahead and plot a bar so to do bar graphs. Well you have to do with MAP plot. Live is you have to just notify map plot live of your intentions basically no matter what you're doing . So if you're doing a regular graph it's fine you do appeal to you that plot and everything's great and all you do is specify a line type if you want to add a marker type and you're good to go. OK. It just so happens the default line type is a straight line so we didn't have to do any of that. If you want to do a scatter plot you have to tell map plot lib. Hey I'm about to throw scatter plot data at you if you want to do a bar chart you have to tell it in advance. Hey about to do O'Barr. So the way that you do that is Piel T Dot. And if you couldn't guess it's bar. So with bar you'd pass again x's and y's so we can do something really simple once you theory and then we can pass a 5 at 3 and 4 5 3 and 4 and it's really that that's all you have to do. So we can actually graph that really quick. And there you go you've got some bars and he price on error. And this is the error you got no labeled objects found. And the reason why we're getting that error is we're asking the legend to show up. But it has nothing to show. So we get that error. It's not a a game stopping error or anything like that. The code will still run and the script will still continue but that's what you're getting. So if you see that error it's because you're asking for a legend and you haven't told it. Ken given the legend anything to display Now we've already got Xs and Ys predefined So let's go ahead and do x y. Good enough. And then let's give it a label and the label will just be one. And then let's go ahead and plot another one P.L. T Dot bar and then keep X.. But this time we'll do y 2 and the label here will be two. Now we can save and run and we'll see a problem. Sure enough there is your problem. You can see that. Well first of all we've got some overlapping data. This is not the best but also we can see in our legend these are different colors. So that's not really helping us either. So for example what we could do is like we could change X. let's change X just for the sake of examples . Two four six eight ten and then we'll make an X 2 is equal to 1 3 5 7 and 9 and the other stuff can stay the same. X x 2 weeks to save and run that one. There we go. So now you've got lots of bars. But again we can't really see like which is which here. So the next thing that we need to change is we can you can change the color of the bar specifically so we can use color equals and for analysis use g. Ok so a G is for green and we can change this one. We can say color equals wups color equals m yenta and we'll say more on that. And there you go. You can see that we've changed the color. And you can see the new color via the legend and I mean is a lot easier to read here. Now of course we probably should keep our eyes at a quick guilty and then X label. And this would be maybe bar number and then LTL y label bar heights. And don't forget your L to label and then peel t title bar chart tutorial. It's always a good idea to make sure you always have labels because otherwise people get confused now . So you get the colors and we've got the labels we've got the legend so it's pretty decent bar chart . They're just a nice simple bar chart and then soon down the road a couple sections later we'll be talking about 3D bar charts ought to be pretty cool. So that's basically all there is to it with a simple bar chart. Now in the next tutorial we're going to be talking about a histogram which is a lot of people kind of consider them to be the same thing but they are pretty fundamentally different. So that's what we've been talking about next and if you don't know the difference between a bar Churton a histogram you're about to go to you for that and thanks for watching.