-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add 'density' kwarg to histogram #8993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/matplotlib/tests/test_axes.py
Outdated
ax.hist((d1, d2), stacked=True, normed=True, density=False) | ||
|
||
|
||
def test_hist_stacked_density(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test needs a different name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was being covered by one of the other added ones anyway, so I've just got rid of it.
Adding strict coverage changes on the tests was a brilliant idea (not sure who suggested that, but I owe them a drink of their choice). |
lib/matplotlib/axes/_axes.py
Outdated
set, then that value will be used. If neither are set, then the | ||
args will be treated as ``False``. | ||
|
||
If both are set to different things, the hist function raises an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be 'if both are set'
@dstansby Can you squash this to three commits (one each for the code from @chelseatroy and @moboehle and a third of your changes)? |
…istent with numpy Reformatted according to pep8 Added tests for density. Style fixes in hist function. Density and normed cannot be set to not None at the same time anymore. Density and normed cannot be set to not None at the same time anymore.
Update documentation to reflect addition of density arg to hist Adjust documentation and test formatting Raise if density and normed are both set in hist Update documentation to match pep8 guidelines
Remove changes to pyplot.py Remove accidental normalize imput method PEP8 new tests Only check for double kwargs once Remove duplicate test and parametrize test Small docstring fix
2e854aa
to
55728ad
Compare
I think that's worked... |
lib/matplotlib/axes/_axes.py
Outdated
normed : boolean, optional | ||
If `True`, the first element of the return tuple will | ||
density : boolean, optional | ||
If ``True``, the first element of the return tuple will | ||
be the counts normalized to form a probability density, i.e., | ||
the area (or integral) under the histogram will sum to 1. | ||
This is achieved dividing the count by the number of observations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is achieved by dividing the
# We will handle the normed kwarg within mpl until we | ||
# get to the point of requiring numpy >= 1.5. | ||
hist_kwargs = dict(range=bin_range) | ||
density = bool(density) or bool(normed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need to cast it to bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If density
/normed
is None
then bool(None)
evaluates to False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't strictly need the cast to bool, but it also does not hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but doesn't if None also evaluate to false when it's not an equality operation?
Going to merge since there's two approvals |
This change is from matplotlib#8993
This change is from matplotlib#8993
This change is from matplotlib#8993
This change is from matplotlib#8993
This is a merge of #7856 and #8408, both of which helped to introduce the
density
kwarg tohistogram
. Will definitely want a squash when it goes in as there were lots of little tricky bits to fix.Fixes #7364