2

I try running the following code

import numpy as np
import matplotlib.pyplot as plt

x = np.random.randn(1000)
plt.hist(x, bins=50, density=True)
plt.show()

And I get the following error message:

AttributeError: Unknown property density

What's wrong?

2
  • What version of matplotlib are you using? Versions < 2 don't have the density argument for hist Commented Feb 8, 2019 at 11:37
  • Older question without answer: stackoverflow.com/questions/51368471/… Commented Feb 8, 2019 at 11:53

1 Answer 1

4

What is the Python version and matplotlib version you are using?

Older versions of matplotlib (e.g. 1.3.1) don't have the density parameter, but instead have the normed parameter. This is probably why you are getting the AttributeError.

To check the matplotlib version, you can simply do:

python -m pip list

Versions of matplotlib above 2.0 all have the density parameter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.