- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a stacked bar chart for my DataFrame using Seaborn in Matplotlib?
To create a stacked bar chart, we can use Seaborn's barplot() method, i.e., show point estimates and confidence intervals with bars.
Create df using Pandas Data Frame.
Using barplot() method, create bar_plot1 and bar_plot2 with color as red and green, and label as count and select.
To enable legend, use legend() method, at the upper-right location.
To display the figuree, use show() method.
Example
import pandas import matplotlib.pylab as plt import seaborn as sns plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pandas.DataFrame(dict( number=[2, 5, 1, 6, 3], count=[56, 21, 34, 36, 12], select=[29, 13, 17, 21, 8] )) bar_plot1 = sns.barplot(x='number', y='count', data=df, label="count", color="red") bar_plot2 = sns.barplot(x='number', y='select', data=df, label="select", color="green") plt.legend(ncol=2, loc="upper right", frameon=True) plt.show()
Output
- Related Articles
- How to Create a Diverging Stacked Bar Chart in Matplotlib?
- How to create a stacked bar chart using JavaFX?
- How to display stacked bar chart using matplotlib in Python?
- How to create stacked bar chart using ggvis in R?
- Horizontal stacked bar chart in Matplotlib
- How to create horizontal stacked bar chart using ggvis in R?
- How to create a 100% stacked Area Chart with Matplotlib?
- How to create a stacked area chart using JavaFX?
- Create stacked bar plot for one categorical variable in an R dataframe.
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.
- How to create a bar chart using JavaFX?
- How to create a Matplotlib bar chart with a threshold line?
- How to create a bar chart for single vector using ggplot2 in R?
- Conditional formatting stacked bar chart in Excel
- How to create a bar chart using plotly in R?

Advertisements