helene
helene

Reputation: 67

Meaning of colors in histogram matplotlib

l have a numpy variable called rnn1 of dimension(37,512)

n, bins, patches = plt.hist(rnn1, histtype='stepfilled')

l got the following histogram shape

histogram

To what the different colors refer ? What is the difference between n and patches

Upvotes: 0

Views: 467

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40737

As the documentation of hist() states: input x can be an array of shape (n,) or a sequence of (n,) arrays. Since you are passing an array of shape (37,512), matplotlib interprets this as a sequence of 512 different (37,)-long arrays. It therefore draws 512 histogram, each with a different color. I'm guessing that's not actually what you were trying to achieve, but that's outside the scope of your question.

The returned value n is a list of 512 arrays, each containing the height of each of the bars in your histograms.

The returned object patch is a list of 512 lists of patches, which are the actual graphical elements that compose the figure.

Upvotes: 3

Related Questions