What are n bins and patches in matplotlib?

I read this in the matplotlib tutorial:

n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)

I'm wondering what are n, bins and patches.

+4
source share
1 answer

I was going to offer reading documents , but this does not provide any additional explanation, although I still advise you to take a look.

  • n: number of samples in each histogram bin
  • bins: left edge of each hopper
  • patches are individual patches used to create a histogram, such as a collection of rectangles

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

n bins ,

+7

Source: https://habr.com/ru/post/1541368/


All Articles