
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to make two histograms have the same bin width in Matplotlib?
To make two histograms having same bin width, we can compute the histogram of a set of data.
Steps
Create random data, a, and normal distribution, b.
Initialize a variable, bins, for the same bin width.
Plot a and bins using hist() method.
Plot b and bins using hist() method.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True a = np.random.random(100) * 0.5 b = 1 - np.random.normal(size=100) * 0.1 bins = 10 bins = np.histogram(np.hstack((a, b)), bins=bins)[1] plt.hist(a, bins, edgecolor='black') plt.hist(b, bins, edgecolor='black') plt.show()
Output
- Related Questions & Answers
- Set two Matplotlib imshow plots to have the same colormap scale
- How to make two markers share the same label in the legend using Matplotlib?
- How to plot two histograms side by side using Matplotlib?
- How to make an OptionMenu maintain the same width using tkinter?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to make several legend keys to the same entry in Matplotlib?
- How to know if two arrays have the same values in JavaScript?
- How to plot two histograms together in R?
- How come two children from the same family have different nature?
- Plotting profile histograms in Python Matplotlib
- How to show two different colored colormaps in the same imshow Matplotlib?
- How to plot histograms from dataframes in Pandas using Matplotlib?
- Check if two String objects have the same value in C#
- How do I make the width of the title box span the entire plot in Matplotlib?
- Plotting histograms against classes in Pandas / Matplotlib
Advertisements