Skip to content

Commit bdcaab5

Browse files
committed
Adjust documentation and test formatting
1 parent 5995c58 commit bdcaab5

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5923,7 +5923,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
59235923
59245924
Default is ``None``
59255925
5926-
normed or density : boolean, optional
5926+
normed, density : boolean, optional
59275927
Either the 'normed' or the 'density' arg can be set to
59285928
accomplish this behavior:
59295929
@@ -5945,19 +5945,21 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
59455945
weights : (n, ) array_like or None, optional
59465946
An array of weights, of the same shape as `x`. Each value in `x`
59475947
only contributes its associated weight towards the bin count
5948-
(instead of 1). If `normed` and/or 'density' is True, the weights are normalized,
5949-
so that the integral of the density over the range remains 1.
5948+
(instead of 1). If `normed` and/or 'density' is True,
5949+
the weights are normalized, so that the integral of the density
5950+
over the range remains 1.
59505951
59515952
Default is ``None``
59525953
59535954
cumulative : boolean, optional
59545955
If `True`, then a histogram is computed where each bin gives the
59555956
counts in that bin plus all bins for smaller values. The last bin
5956-
gives the total number of datapoints. If `normed` and/or 'density' is also `True`
5957-
then the histogram is normalized such that the last bin equals 1.
5958-
If `cumulative` evaluates to less than 0 (e.g., -1), the direction
5959-
of accumulation is reversed. In this case, if `normed` and/or 'density' is also
5960-
`True`, then the histogram is normalized such that the first bin
5957+
gives the total number of datapoints. If `normed` and/or 'density'
5958+
is also `True` then the histogram is normalized such that the last
5959+
bin equals 1. If `cumulative` evaluates to less than 0 (e.g., -1),
5960+
the direction of accumulation is reversed. In this case, if
5961+
`normed` and/or 'density' is also `True`, then the histogram is
5962+
normalized such that the first bin
59615963
equals 1.
59625964
59635965
Default is ``False``
@@ -6077,12 +6079,14 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
60776079
60786080
"""
60796081

6080-
# This sets the density variable, if necessary, to its predecessor, 'normed.'
6081-
if density != None and normed != None and density != normed:
6082-
raise ValueError('The density and normed arguments represent the same concept. Please set only one of them, or set them to the same value.')
6083-
elif normed != None and density == None:
6082+
# Sets the density variable, if necessary, to its predecessor, 'normed.'
6083+
if density is not None and normed is not None and density is not normed:
6084+
raise ValueError('The density and normed arguments represent the '
6085+
'same concept. Please set only one of them, or '
6086+
'set them to the same value.')
6087+
elif normed is not None and density is None:
60846088
density = normed
6085-
elif normed == None and density == None:
6089+
elif normed is None and density is None:
60866090
density = False
60876091

60886092
def _normalize_input(inp, ename='input'):

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,13 +2541,13 @@ def test_hist_stacked_normed():
25412541
ax = fig.add_subplot(111)
25422542
ax.hist((d1, d2), stacked=True, normed=True)
25432543

2544+
25442545
@image_comparison(baseline_images=['hist_stacked_normed'])
25452546
def test_hist_stacked_density():
25462547
# make some data
25472548
d1 = np.linspace(1, 3, 20)
25482549
d2 = np.linspace(0, 10, 50)
2549-
fig = plt.figure()
2550-
ax = fig.add_subplot(111)
2550+
fig, ax = plt.subplots()
25512551
ax.hist((d1, d2), stacked=True, density=True)
25522552

25532553
with pytest.raises(ValueError):
@@ -3274,6 +3274,10 @@ def test_specgram_angle_freqs():
32743274
noverlap=noverlap, pad_to=pad_to, sides='onesided',
32753275
mode='phase', scale='dB')
32763276

3277+
with pytest.raises(ValueError):
3278+
ax13.specgram(y, NFFT=NFFT, Fs=Fs,
3279+
noverlap=noverlap, pad_to=pad_to, sides='twosided',
3280+
mode='phase', scale='dB')
32773281

32783282

32793283
@image_comparison(baseline_images=['specgram_angle_noise'],

0 commit comments

Comments
 (0)