10

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

1 Answer 1

17

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 histogram
  • bins: is the left hand edge of each bin
  • patchesis the individual patches used to create the histogram, e.g a collection of rectangles

The 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()

enter image description here

In general the n and bins are used for subsequent data analysis as in this demo

1
  • Could you put in a quick PR at add that to the hist docstring?
    – tacaswell
    May 21, 2014 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.