Skip to content

plt.hist density argument does not function as described. #10398

Closed
@ryanpeach

Description

@ryanpeach

Bug report

Bug summary

plt.hist density argument does not function as described.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
x = np.asarray([0,0,0,0,1,1,2,2,2,2,3,3,3,3,3,3,3], dtype="float")
n, bins, _ = plt.hist(x, density=1, bins=2)
print(n)
print(np.sum(n))

Actual outcome

[0.23529412 0.43137255]
0.6666666666666666

Expected outcome

import matplotlib.pyplot as plt
import numpy as np
x = np.asarray([0,0,0,0,1,1,2,2,2,2,3,3,3,3,3,3,3], dtype="float")
n, bins, _ = plt.hist(x, density=1, bins=2)
n /= np.sum(n)  # As advertised
print(n)
print(np.sum(n))
[0.35294118 0.64705882]
1.0

Matplotlib version

  • Operating system: OSX High Sierra
  • Matplotlib version: 2.1.1
  • Matplotlib backend: MacOSX
  • Python version: 3.6.4
  • Other libraries: numpy 1.14.0
  • Installed via: pip3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions