Hello. This time I would like to take a look at the hist method inside the matplotlib module. What was surprising to me was that this function returned three return values. Let's start with the sample code!
hist_sample.py
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(123)
mu = 10 #Average value
sigma = 15 #standard deviation
#Create 1000 random numbers that follow a normal distribution with a mean value of 10 and a standard deviation of 15.
x = np.random.normal(mu, sigma, 1000)
#Drawing object (fig)And subplot(ax)Created.
fig, ax = plt.subplots()
#Draw a histogram here! And there are three return values.
n, bins, patches = ax.hist(x)
plt.show()
result:
** How beautiful. ** **
There are three return values: * n, bins, patches *. Let's look at each one.
--n (array) --Represents the number on the vertical axis. --If you add all the elements, you get 1000 in the above code.
--bins (array) --Coordinates that are the breaks on the horizontal axis --The default size is 10. --ex: [51.3, 61.3, 71.3, ・ ・ ・]
Is the histogram an elementary school? It is also effective as a graph. I think it's better to master it so that it can be visualized quickly. Also, if you want to arrange the histogram Qiita: How to draw a histogram with Matplotlib was very helpful.
Recommended Posts