I read this in the matplotlib tutorial:
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
I am wondering what are n, bins, and patches
It is a type of bar graph. To construct a histogram, the first step is to “bin” the range of values — that is, divide the entire range of values into a series of intervals — and then count how many values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable.
The matplotlib. patches. Rectangle class is used to rectangle patch to a plot with lower left at xy = (x, y) with specified width, height and rotation angle.
%matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.
I was going to suggest reading the docs but this provides no extra explanation although I still advise you have a look.
n
: is the number of counts in each bin of the histogrambins
: is the left hand edge of each binpatches
is the individual patches used to create the histogram, e.g a collection of rectanglesThe patches can be used to change the properties of individual bars as in these examples. Here is a simple example of its use
import numpy as np
import matplotlib.pyplot as plt
x = np.random.normal(size=100)
n, bins, patches = plt.hist(x)
plt.setp(patches[0], 'facecolor', 'g')
plt.show()
In general the n
and bins
are used for subsequent data analysis as in this demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With