[PYTHON] About the return value of the histogram.

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!

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: ダウンロード.png

** How beautiful. ** **

Description of the return value

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, ・ ・ ・]

Summary

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

About the return value of the histogram.
About the return value of pthread_mutex_init ()
Watch out for the return value of __len__
About the ease of Python
About the components of Luigi
About the features of Python
The story that the return value of tape.gradient () was None
Find the definition of the value of errno
Check the return value using PEP 380
About the basic type of Go
About the upper limit of threads-max
About the behavior of yield_per of SqlAlchemy
About the size of matplotlib points
About the basics list of Python basics
About the behavior of enable_backprop of Chainer v2
About the virtual environment of python version 3.7
About the arguments of the setup function of PyCaret
About the Normal Equation of Linear Regression
Get the value of the middle layer of NN
Make the default value of the argument immutable
Get the return value of an external shell script (ls) with python3
About the queue
About the accuracy of Archimedean circle calculation method
About the behavior of copy, deepcopy and numpy.copy
About the processing speed of SVM (SVC) of scikit-learn
The value of pyTorch torch.var () is not distributed
Try singular value decomposition of the daimyo matrix
A note about the python version of python virtualenv
Find the divisor of the value entered in python
About the development contents of machine learning (Example)
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Search by the value of the instance in the list
About the behavior of Queue during parallel processing
About the * (asterisk) argument of python (and itertools.starmap)
[Python] Summary of functions that return the index that takes the closest value in the array
The beginning of cif2cell
A memorandum about the warning of the pylint output result
[Python of Hikari-] Chapter 06-02 Function (argument and return value 1)
About all of numpy
The meaning of self
[Python] Calculate the average value of the pixel value RGB of the object
Return value of quit ()-Is there anything returned by the "function that ends everything"?
About assignment of numpy.ndarray
About MultiIndex of pandas
the zen of Python
Think about the next generation of Rack and WSGI
About testing in the implementation of machine learning models
Get the return code of the Python script from bat
About the inefficiency of data transfer in luigi on-memory
[C language] [Linux] Get the value of environment variable
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Make the default value of the argument immutable (article explanation)
The story of sys.path.append ()
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
[Golang] Specify an array in the value of map
About the Unfold function
About the service command
About the uncluttered arrangement in the import order of flake8
A story about changing the master name of BlueZ
About variable of chainer