Handle single color for multiple datasets in `hist` by gapplef · Pull Request #30867 · matplotlib/matplotlib · GitHub
Skip to content
Merged
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/release/next_whats_new/hist_color.rst
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7326,6 +7326,9 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
Color or sequence of colors, one per dataset. Default (``None``)
uses the standard line color sequence.

.. versionadded:: 3.10
It is now possible to use a single color with multiple datasets.

label : str or list of str, optional
String, or sequence of strings to match multiple datasets. Bar
charts yield multiple patches per dataset, but only the first gets
Expand Down Expand Up @@ -7447,6 +7450,8 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
if color is None:
colors = [self._get_lines.get_next_color() for i in range(nx)]
else:
if mcolors.is_color_like(color):
color = [color]*nx
colors = mcolors.to_rgba_array(color)
if len(colors) != nx:
raise ValueError(f"The 'color' keyword argument must have one "
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Loading