Matplotlib Bars
Learn all about Matplotlib Bars in this comprehensive tutorial.
- •With Pyplot, you can use the bar() function to draw bar graphs:
- •If you want the bars to be displayed horizontally instead of vertically, use the barh() function:
- •The bar() and barh() take the keyword argument color to set the color of the bars:
- •The bar() takes the keyword argument width to set the width of the bars:
- •The barh() takes the keyword argument height to set the height of the bars:
Creating Bars
With Pyplot, you can use the bar() function to draw bar graphs:
The bar() function takes arguments that describes the layout of the bars.
The categories and their values represented by the first and second argument as arrays.
Horizontal Bars
If you want the bars to be displayed horizontally instead of vertically, use the barh() function:
Bar Color
The bar() and barh() take the keyword argument color to set the color of the bars:
You can use any of the 140 supported color names.
Or you can use Hexadecimal color values:
Bar Width
The bar() takes the keyword argument width to set the width of the bars:
The default width value is 0.8
Bar Height
The barh() takes the keyword argument height to set the height of the bars:
The default height value is 0.8
Module quiz
2 questionsWhich of the following is true about Matplotlib Bars?
What is the most common pitfall when working with Matplotlib Bars?
Answer all questions to submit.