- 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 do I plot two countplot graphs side by side in Seaborn using Matplotlib?
To plot two countplot graphs side by side in Seaborn, we can take the following steps −
To create two graphs, we can use nrows=1, ncols=2 with figure size (7, 7).
Create a dataframe with keys, col1 and col2, using Pandas.
Use countplot() to show the counts of observations in each categorical bin using bars.
Adjust the padding between and around the subplots.
To display the figure, use show() method.
Example
import pandas as pd import numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True f, axes = plt.subplots(1, 2) df = pd.DataFrame(dict(col1=np.linspace(1, 10, 5), col2=np.linspace(1, 10, 5))) sns.countplot(df.col1, x='col1', color="red", ax=axes[0]) sns.countplot(df.col2, x="col2", color="green", ax=axes[1]) plt.show()
Output
- Related Articles
- How to plot two Seaborn lmplots side-by-side (Matplotlib)?
- How to plot two histograms side by side using Matplotlib?
- How to plot bar graphs with same X coordinates side by side in Matplotlib?
- How do I keep two side-by-side div elements the same height?
- How to make two plots side-by-side using Python?
- How to limit the number of groups shown in a Seaborn countplot using Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How to plot multiple graphs in Matplotlib?
- How we can put two divisions side by side in HTML?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How do I plot hatched bars using Pandas and Matplotlib?
- How do I plot Shapely polygons and objects using Matplotlib?
- Add minor gridlines to Matplotlib plot using Seaborn
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?

Advertisements