- 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 plot two histograms side by side using Matplotlib?
To plot two histograms side by side using matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Make two dataframes, df1 and df2, of two-dimensional, size-mutable, potentially heterogeneous tabular data.
Create a figure and a set of subplots.
Make a histogram of the DataFrame's, df1 and df2.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df1 = pd.DataFrame(dict(a=[1, 1, 1, 1, 3])) df2 = pd.DataFrame(dict(b=[1, 1, 2, 1, 3])) fig, axes = plt.subplots(1, 2) df1.hist('a', ax=axes[0]) df2.hist('b', ax=axes[1]) plt.show()
Output
- Related Articles
- How to plot two Seaborn lmplots side-by-side (Matplotlib)?
- How do I plot two countplot graphs side by side in Seaborn using Matplotlib?
- How to create side by side histograms in base R?
- How to plot bar graphs with same X coordinates side by side in Matplotlib?
- How to make two plots side-by-side using Python?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot histograms from dataframes in Pandas using Matplotlib?
- How we can put two divisions side by side in HTML?
- How to plot two histograms together in R?
- How to move the Y-axis ticks from the left side of the plot to the right side in matplotlib?
- How to align images side by side with CSS?
- How do I keep two side-by-side div elements the same height?
- How to create side-by-side boxplot in base R?
- How to create side by side barplot in base R?
- How can matplotlib be used to create histograms using Python?

Advertisements