Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Aug 7, 2017
Merged

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Aug 5, 2017

This is a merge of #7856 and #8408, both of which helped to introduce the density kwarg to histogram. Will definitely want a squash when it goes in as there were lots of little tricky bits to fix.

Fixes #7364

@tacaswell
Copy link
Member

ax.hist((d1, d2), stacked=True, normed=True, density=False)


def test_hist_stacked_density():
Copy link
Member

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.

Copy link
Member Author

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.

@tacaswell
Copy link
Member

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).

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
Copy link
Member

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'

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Aug 5, 2017
@tacaswell
Copy link
Member

@dstansby Can you squash this to three commits (one each for the code from @chelseatroy and @moboehle and a third of your changes)?

moboehle and others added 3 commits August 5, 2017 18:25
…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
@dstansby
Copy link
Member Author

dstansby commented Aug 5, 2017

I think that's worked...

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
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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?

@dstansby
Copy link
Member Author

dstansby commented Aug 7, 2017

Going to merge since there's two approvals

@dstansby dstansby merged commit 0a2324e into matplotlib:master Aug 7, 2017
@dstansby dstansby deleted the hist-kwarg-fix branch August 7, 2017 20:49
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Aug 27, 2017
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Aug 27, 2017
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Aug 27, 2017
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram compatibility with numpy
5 participants