

- 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 have logarithmic bins in a Python histogram?
We can set the logarithmic bins while plotting histogram using plt.hist(bin="").
Steps
Create an array x, where range is 100.
Plot a histogram using plt.hist() method. We can pass logarithmic bins using logarithmic bins that returns numbers spaced evenly on a log scale.
Get the current axes, creating one if necessary and set the X-axis scale.
To show the figure, use plt.show() method.
Example
from matplotlib import pyplot as plt import numpy as np x = np.array(range(100)) plt.hist(x, bins=np.logspace(start=np.log10(10), stop=np.log10(15), num=10)) plt.gca().set_xscale("log") plt.show()
Output
- Related Questions & Answers
- Logarithmic Y-axis bins in Python
- How to create a histogram without bins in base R?
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- How to make a histogram with bins of equal area in Matplotlib?
- Getting information for bins in Matplotlib histogram function
- How to normalize a histogram in Python?
- How to make a log histogram in Python?
- How to save a histogram plot in Python?
- How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?
- How to create bins for a continuous vector in R?
- How to visualize values on logarithmic scale on matplotalib?
- How to plot a 2D histogram in Matplotlib?
- Circular (polar) histogram in Python
- How to create normal quantile-quantile plot for a logarithmic model in R?
- How to show the Logarithmic plot of a cumulative distribution function in Matplotlib?
Advertisements