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

Skip to content

Commit c8ed7ba

Browse files
committed
Merge v1.4.x into master
2 parents d92d2ad + 924d06b commit c8ed7ba

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
unicode_literals)
33

44
import six
5-
from six.moves import reduce, xrange, zip
5+
from six.moves import reduce, xrange, zip, zip_longest
66

77
import math
88
import warnings
9-
import itertools
109

1110
import numpy as np
1211
from numpy import ma
@@ -5416,14 +5415,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54165415
Input values, this takes either a single array or a sequency of
54175416
arrays which are not required to be of the same length
54185417
5419-
bins : integer or array_like, optional, default: 10
5418+
bins : integer or array_like, optional
54205419
If an integer is given, `bins + 1` bin edges are returned,
54215420
consistently with :func:`numpy.histogram` for numpy version >=
54225421
1.3.
54235422
54245423
Unequally spaced bins are supported if `bins` is a sequence.
54255424
5426-
range : tuple, optional, default: None
5425+
default is 10
5426+
5427+
range : tuple or None, optional
54275428
The lower and upper range of the bins. Lower and upper outliers
54285429
are ignored. If not provided, `range` is (x.min(), x.max()). Range
54295430
has no effect if `bins` is a sequence.
@@ -5432,20 +5433,26 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54325433
is based on the specified bin range instead of the
54335434
range of x.
54345435
5435-
normed : boolean, optional, default: False
5436+
Default is ``None``
5437+
5438+
normed : boolean, optional
54365439
If `True`, the first element of the return tuple will
54375440
be the counts normalized to form a probability density, i.e.,
54385441
``n/(len(x)`dbin)``, i.e., the integral of the histogram will sum
54395442
to 1. If *stacked* is also *True*, the sum of the histograms is
54405443
normalized to 1.
54415444
5442-
weights : array_like, shape (n, ), optional, default: None
5445+
Default is ``False``
5446+
5447+
weights : (n, ) array_like or None, optional
54435448
An array of weights, of the same shape as `x`. Each value in `x`
54445449
only contributes its associated weight towards the bin count
54455450
(instead of 1). If `normed` is True, the weights are normalized,
54465451
so that the integral of the density over the range remains 1.
54475452
5448-
cumulative : boolean, optional, default : False
5453+
Default is ``None``
5454+
5455+
cumulative : boolean, optional
54495456
If `True`, then a histogram is computed where each bin gives the
54505457
counts in that bin plus all bins for smaller values. The last bin
54515458
gives the total number of datapoints. If `normed` is also `True`
@@ -5455,13 +5462,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54555462
`True`, then the histogram is normalized such that the first bin
54565463
equals 1.
54575464
5458-
bottom : array_like, scalar, or None, default: None
5465+
Default is ``False``
5466+
5467+
bottom : array_like, scalar, or None
54595468
Location of the bottom baseline of each bin. If a scalar,
54605469
the base line for each bin is shifted by the same amount.
54615470
If an array, each bin is shifted independently and the length
54625471
of bottom must match the number of bins. If None, defaults to 0.
54635472
5464-
histtype : ['bar' | 'barstacked' | 'step' | 'stepfilled'], optional
5473+
Default is ``None``
5474+
5475+
histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
54655476
The type of histogram to draw.
54665477
54675478
- 'bar' is a traditional bar-type histogram. If multiple data
@@ -5476,7 +5487,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54765487
- 'stepfilled' generates a lineplot that is by default
54775488
filled.
54785489
5479-
align : ['left' | 'mid' | 'right'], optional, default: 'mid'
5490+
Default is 'bar'
5491+
5492+
align : {'left', 'mid', 'right'}, optional
54805493
Controls how the histogram is plotted.
54815494
54825495
- 'left': bars are centered on the left bin edges.
@@ -5485,34 +5498,47 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
54855498
54865499
- 'right': bars are centered on the right bin edges.
54875500
5488-
orientation : ['horizontal' | 'vertical'], optional
5501+
Default is 'mid'
5502+
5503+
orientation : {'horizontal', 'vertical'}, optional
54895504
If 'horizontal', `~matplotlib.pyplot.barh` will be used for
54905505
bar-type histograms and the *bottom* kwarg will be the left edges.
54915506
5492-
rwidth : scalar, optional, default: None
5507+
rwidth : scalar or None, optional
54935508
The relative width of the bars as a fraction of the bin width. If
5494-
`None`, automatically compute the width. Ignored if `histtype` =
5495-
'step' or 'stepfilled'.
5509+
`None`, automatically compute the width.
54965510
5497-
log : boolean, optional, default : False
5511+
Ignored if `histtype` is 'step' or 'stepfilled'.
5512+
5513+
Default is ``None``
5514+
5515+
log : boolean, optional
54985516
If `True`, the histogram axis will be set to a log scale. If `log`
54995517
is `True` and `x` is a 1D array, empty bins will be filtered out
55005518
and only the non-empty (`n`, `bins`, `patches`) will be returned.
55015519
5502-
color : color or array_like of colors, optional, default: None
5520+
Default is ``False``
5521+
5522+
color : color or array_like of colors or None, optional
55035523
Color spec or sequence of color specs, one per dataset. Default
55045524
(`None`) uses the standard line color sequence.
55055525
5506-
label : string, optional, default: ''
5526+
Default is ``None``
5527+
5528+
label : string or None, optional
55075529
String, or sequence of strings to match multiple datasets. Bar
55085530
charts yield multiple patches per dataset, but only the first gets
55095531
the label, so that the legend command will work as expected.
55105532
5511-
stacked : boolean, optional, default : False
5533+
default is ``None``
5534+
5535+
stacked : boolean, optional
55125536
If `True`, multiple data are stacked on top of each other If
55135537
`False` multiple data are aranged side by side if histtype is
55145538
'bar' or on top of each other if histtype is 'step'
55155539
5540+
Default is ``False``
5541+
55165542
Returns
55175543
-------
55185544
n : array or list of arrays
@@ -5868,16 +5894,10 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
58685894
labels = [None]
58695895
elif is_string_like(label):
58705896
labels = [label]
5871-
elif is_sequence_of_strings(label):
5872-
labels = list(label)
58735897
else:
5874-
raise ValueError(
5875-
'invalid label: must be string or sequence of strings')
5876-
5877-
if len(labels) < nx:
5878-
labels += [None] * (nx - len(labels))
5898+
labels = [str(lab) for lab in label]
58795899

5880-
for (patch, lbl) in zip(patches, labels):
5900+
for (patch, lbl) in zip_longest(patches, labels, fillvalue=None):
58815901
if patch:
58825902
p = patch[0]
58835903
p.update(kwargs)

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,11 @@ def test_color_None():
34803480
ax.plot([1,2], [1,2], color=None)
34813481
plt.show()
34823482

3483+
@cleanup
3484+
def test_numerical_hist_label():
3485+
fig, ax = plt.subplots()
3486+
ax.hist([range(15)] * 5, label=range(5))
3487+
34833488
if __name__ == '__main__':
34843489
import nose
34853490
import sys

0 commit comments

Comments
 (0)