Write a log-scale histogram on the x-axis in python

Note that X-axis draws log scale graph in python

import pylab as pl
import numpy as np

Creating a distribution with two peaks

data1 = (np.random.normal(size=100) + 10)* 1e-5
data2 = (np.random.normal(size=100) + 10)* 1e-10
data = np.r_[data1, data2]
#Histogram creation
print(data)
pl.hist(data)

Unknown-6.png

You can't just make x a log scale

pl.hist(data)
pl.gca().set_xscale("log")

Unknown.png

The width of each bar (also called bins) is not logarithmic, I see.

#Histogram creation
print(data)
pl.hist(data, bins=np.logspace(-11, -3, 500))
pl.gca().set_xscale("log")

Unknown2.png

I got it. The option of np.logspace is like "Create 500 bins in the range of 10 ^ -11 to 10 ^ 3".

Recommended Posts

Write a log-scale histogram on the x-axis in python
Write the test in a python docstring
Write a binary search in Python
Write A * (A-star) algorithm in Python
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
Write a short property definition in Python
Run the Python interpreter in a script
Write a Caesar cipher program in Python
Write a simple greedy algorithm in Python
Write a simple Vim Plugin in Python 3
[Python] A progress bar on the terminal
Get the number of readers of a treatise on Mendeley in Python
[Python] Get the files in a folder with Python
Get the caller of a function in Python
Make a copy of the list in Python
A note on optimizing blackbox functions in Python
The trick to write flatten concisely in python
Output in the form of a python array
To write to Error Repoting in Python on GAE
[Python] How to draw a histogram in Matplotlib
[Python] Find the transposed matrix in a comprehension
Write Python in MySQL
Check if the string is a number in python
Basic information Write the 2018 fall algorithm problem in Python
Write a super simple molecular dynamics program in python
I want to write in Python! (2) Let's write a test
Until drawing a 3D graph in Python on windows10
Make a breakpoint on the c layer with python
Write letters in the card illustration with OpenCV python
I want to write in Python! (3) Utilize the mock
A note on handling variables in Python recursive functions
Display a histogram of image brightness values in python
A reminder about the implementation of recommendations in Python
What does the last () in a function mean in Python?
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
A note on the library implementation that explores hyperparameters using Bayesian optimization in Python
Take a screenshot in Python
Write Pandoc filters in Python
Create a function in Python
Create a dictionary in Python
Download the file in Python
Find the difference in Python
Write beta distribution in Python
Write python in Rstudio (reticulate)
Make a bookmarklet in Python
Draw a heart in Python
A note on the default behavior of collate_fn in PyTorch
Test.py is not reflected on the web server in Python3.
Find out the apparent width of a string in python
Create a local scope in Python without polluting the namespace
Create a list in Python with all followers on twitter
How to use the __call__ method in a Python class
Write a python program to find the editing distance [python] [Levenshtein distance]
Get the number of specific elements in a python list
A note on touching Microsoft's face recognition API in Python
[Note] Import of a file in the parent directory in Python
How to get the last (last) value in a list in Python
To write a test in Go, first design the interface
Find the eigenvalues of a real symmetric matrix in Python