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

Skip to content

Commit be03469

Browse files
committed
For single datasets, don't wrap artist added by Axes.hist in silent_list
See details in changelog note.
1 parent 7af52fe commit be03469

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
When using a single dataset, `Axes.hist` no longer wraps the added artist in a `silent_list`
2+
````````````````````````````````````````````````````````````````````````````````````````````
3+
4+
When `Axes.hist()` is called with a single dataset, it adds to the axes either
5+
a `BarCollection` object (when ``histtype="bar"`` or ``"barstacked"``), or a
6+
`Polygon` object (when ``histype="step"`` or ``"stepfilled"``) -- the latter
7+
being wrapped in a list-of-one-element. Previously, either artist would be
8+
wrapped in a `silent_list`. This is no longer the case: the `BarCollection` is
9+
now returned as is (this is an API breaking change if you were directly relying
10+
on the concrete `list` API; however, `BarCollection` inherits from `tuple` so
11+
most common operations remain available), and the list-of-one `Polygon` is
12+
returned as is. This makes the `repr` of the returned artist more accurate: it
13+
is now ::
14+
15+
<BarContainer object of of 10 artists> # "bar", "barstacked"
16+
[<matplotlib.patches.Polygon object at 0xdeadbeef>] # "step", "stepfilled"
17+
18+
instead of ::
19+
20+
<a list of 10 Patch objects> # "bar", "barstacked"
21+
<a list of 1 Patch objects> # "step", "stepfilled"
22+
23+
When `Axes.hist()` is called with multiple artists, it still wraps its return
24+
value in a `silent_list`, but uses more accurate type information ::
25+
26+
<a list of 3 BarContainer objects> # "bar", "barstacked"
27+
<a list of 3 List[Polygon] objects> # "step", "stepfilled"
28+
29+
instead of ::
30+
31+
<a list of 3 Lists of Patches objects> # "bar", "barstacked"
32+
<a list of 3 Lists of Patches objects> # "step", "stepfilled"

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,7 +6351,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63516351
orientation='vertical', rwidth=None, log=False,
63526352
color=None, label=None, stacked=False, normed=None,
63536353
**kwargs):
6354-
"""
6354+
r"""
63556355
Plot a histogram.
63566356
63576357
Compute and draw the histogram of *x*. The return value is a tuple
@@ -6550,9 +6550,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65506550
edge of last bin). Always a single array even when multiple data
65516551
sets are passed in.
65526552
6553-
patches : list or list of lists
6554-
Silent list of individual patches used to create the histogram
6555-
or list of such list if multiple input datasets.
6553+
patches : `.BarContainer` or list of single `.Polygon`\s or list of \
6554+
such objects
6555+
Container of individual artists used to create the histogram
6556+
or list of such containers if there are multiple input datasets.
65566557
65576558
Other Parameters
65586559
----------------
@@ -6865,9 +6866,11 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
68656866
p.set_label('_nolegend_')
68666867

68676868
if nx == 1:
6868-
return tops[0], bins, cbook.silent_list('Patch', patches[0])
6869+
return tops[0], bins, patches[0]
68696870
else:
6870-
return tops, bins, cbook.silent_list('Lists of Patches', patches)
6871+
patch_type = ("BarContainer" if histtype.startswith("bar")
6872+
else "List[Polygon]")
6873+
return tops, bins, cbook.silent_list(patch_type, patches)
68716874

68726875
@_preprocess_data(replace_names=["x", "y", "weights"])
68736876
@cbook._rename_parameter("3.1", "normed", "density")

0 commit comments

Comments
 (0)