Skip to content

Change hist(cumulative=-1) to hist(cumulative='reversed') #14650

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2019-06-29-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

Passing negative numbers to ``hist(cumulative=...)`` is deprecated. Pass the
string 'reversed' instead.
2 changes: 1 addition & 1 deletion examples/statistics/histogram_cumulative.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
ax.plot(bins, y, 'k--', linewidth=1.5, label='Theoretical')

# Overlay a reversed cumulative histogram.
ax.hist(x, bins=bins, density=True, histtype='step', cumulative=-1,
ax.hist(x, bins=bins, density=True, histtype='step', cumulative='reversed',
label='Reversed emp.')

# tidy up the figure
Expand Down
16 changes: 11 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6415,18 +6415,17 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,

(or you may alternatively use `~.bar()`).

cumulative : bool or -1, optional
cumulative : bool or 'reversed', optional
If ``True``, then a histogram is computed where each bin gives the
counts in that bin plus all bins for smaller values. The last bin
gives the total number of datapoints.

If *density* is also ``True`` then the histogram is normalized such
that the last bin equals 1.

If *cumulative* is a number less than 0 (e.g., -1), the direction
of accumulation is reversed. In this case, if *density* is also
``True``, then the histogram is normalized such that the first bin
equals 1.
If *cumulative* is 'reversed', the direction of accumulation is
reversed. In this case, if *density* is also ``True``, then the
histogram is normalized such that the first bin equals 1.

Default is ``False``

Expand Down Expand Up @@ -6647,7 +6646,14 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
m[:] = (m / db) / tops[-1].sum()
if cumulative:
slc = slice(None)
if cumulative == 'reversed':
slc = slice(None, None, -1)
if isinstance(cumulative, Number) and cumulative < 0:
cbook.warn_deprecated("3.2",
message="Passing negative numbers to "
"hist(cumulative=...) is "
"deprecated. Pass 'reversed' "
"instead.")
slc = slice(None, None, -1)

if density:
Expand Down