Create a stacked bar plot in Matplotlib
In this article, we will learn how to Create a stacked bar plot in Matplotlib. Let’s discuss some concepts :
- Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure with the broader SciPy stack.
- A bar plot or bar graph may be a graph that represents the category of knowledge with rectangular bars with lengths and heights that’s proportional to the values which they represent. The bar plots are often plotted horizontally or vertically.
- Stacked bar plots represent different groups on the highest of 1 another. The peak of the bar depends on the resulting height of the mixture of the results of the groups. It goes from rock bottom to the worth rather than going from zero to value.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
- Import Library (Matplotlib)
- Import / create data.
- Plot the bars in the stack manner.
Example 1: (Simple stacked bar plot)
Example 2: (Stacked bar chart with more than 2 data)
Example 3: (Stacked Bar chart using dataframe plot)
Team Round 1 Round 2 Round 3 Round 4 0 A 10 20 10 26 1 B 20 25 15 21 2 C 12 15 19 6 3 D 10 18 11 19