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

Skip to content

DOC: reword density desc in ax.hist #16149

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 2 commits into from
Jan 8, 2020

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jan 7, 2020

PR Summary

Changed the docstring of the density kwarg to be a little clearer and to avoid the phrase "sum to 1" , which a quick read could make one think the histogram should sum to 1.

Closes #16147 (?)

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak changed the title DOC: reword density desc DOC: reword density desc in ax.hist Jan 7, 2020
@ImportanceOfBeingErnest
Copy link
Member

I'm +0 for changing "sum" into "integrate".

I'm +1 on showing the formula, however, it should use the nomenclature of the return (which currently is n, not h) and also should not use the assigment =, so probably np.sum(n * np.diff(bins)) == 1

I'm -1 on deleting the sentence on how the density is computed; although it could of course be reformulated to be less ambiguous.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's better.

Edit: I also agree with Ernest's comments :)

@jklymak
Copy link
Member Author

jklymak commented Jan 7, 2020

I don't see that the "how" its computed really makes things clearer. For reference, here is numpy's doc:

If False, the result will contain the number of samples in each bin. If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability mass function.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html

@jklymak jklymak force-pushed the doc-reword-hist-density branch 2 times, most recently from 2d63baf to 6c3d269 Compare January 7, 2020 22:46
@jklymak jklymak force-pushed the doc-reword-hist-density branch from 6c3d269 to 115348f Compare January 7, 2020 22:46
@jklymak
Copy link
Member Author

jklymak commented Jan 7, 2020

OK< changed to

              If ``True``, the first element of the return tuple will
           be the raw counts per bin normalized to form a probability density
             so that the area under the histogram will integrate to 1, i.e.
             ``np.sum(n * np.diff(bins)) == 1``.  (Computed by dividing the
             raw counts ``n0`` by the total number of data points and
             multiplying by the bin width: ``n = n0 / sum(n0) * np.diff(bins)``)

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@NelleV
Copy link
Member

NelleV commented Jan 8, 2020

Thanks @jklymak !

@NelleV NelleV merged commit 3574feb into matplotlib:master Jan 8, 2020
@timhoffm timhoffm added this to the v3.3.0 milestone Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pp.hist paremeter 'density' does not scale data appropriately
5 participants