
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot Multiple Histograms on Same Plot with Seaborn Using Matplotlib
To plot multiple histograms on same plot with Seaborn, we can take the following steps −
Create two lists (x and y).
Create a figure and add a set of two subplots.
Iterate a list consisting of x and y.
Plot a histogram with histplot() method using the data in the list (step 3).
Limit the X-axis range from 0 to 10.
To display the figure, use show() method.
Example
import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 5, 1, 4, 2] y = [7, 5, 6, 4, 5] fig, ax = plt.subplots() for a in [x, y]: sns.histplot(a, bins=4, ax=ax, kde=False) ax.set_xlim([0, 10]) plt.show()
Output
Advertisements