@@ -702,6 +702,11 @@ def __init__(self, ax, *args,
702
702
self ._extend_min = self .extend in ['min' , 'both' ]
703
703
self ._extend_max = self .extend in ['max' , 'both' ]
704
704
if self .colors is not None :
705
+ if mcolors .is_color_like (self .colors ):
706
+ color_sequence = [self .colors ]
707
+ else :
708
+ color_sequence = self .colors
709
+
705
710
ncolors = len (self .levels )
706
711
if self .filled :
707
712
ncolors -= 1
@@ -718,19 +723,19 @@ def __init__(self, ax, *args,
718
723
total_levels = (ncolors +
719
724
int (self ._extend_min ) +
720
725
int (self ._extend_max ))
721
- if (len (self . colors ) == total_levels and
726
+ if (len (color_sequence ) == total_levels and
722
727
(self ._extend_min or self ._extend_max )):
723
728
use_set_under_over = True
724
729
if self ._extend_min :
725
730
i0 = 1
726
731
727
- cmap = mcolors .ListedColormap (self . colors [i0 :None ], N = ncolors )
732
+ cmap = mcolors .ListedColormap (color_sequence [i0 :None ], N = ncolors )
728
733
729
734
if use_set_under_over :
730
735
if self ._extend_min :
731
- cmap .set_under (self . colors [0 ])
736
+ cmap .set_under (color_sequence [0 ])
732
737
if self ._extend_max :
733
- cmap .set_over (self . colors [- 1 ])
738
+ cmap .set_over (color_sequence [- 1 ])
734
739
735
740
# label lists must be initialized here
736
741
self .labelTexts = []
@@ -1498,10 +1503,12 @@ def _initialize_x_y(self, z):
1498
1503
The sequence is cycled for the levels in ascending order. If the
1499
1504
sequence is shorter than the number of levels, it's repeated.
1500
1505
1501
- As a shortcut, single color strings may be used in place of
1502
- one-element lists, i.e. ``'red'`` instead of ``['red']`` to color
1503
- all levels with the same color. This shortcut does only work for
1504
- color strings, not for other ways of specifying colors.
1506
+ As a shortcut, single color may be used in place of one-element lists, i.e.
1507
+ ``'red'`` instead of ``['red']`` to color all levels with the same color.
1508
+
1509
+ .. versionchanged:: 3.10
1510
+ Previously a single color had to be expressed as a string, but now any
1511
+ valid color format may be passed.
1505
1512
1506
1513
By default (value *None*), the colormap specified by *cmap*
1507
1514
will be used.
@@ -1569,10 +1576,10 @@ def _initialize_x_y(self, z):
1569
1576
1570
1577
An existing `.QuadContourSet` does not get notified if
1571
1578
properties of its colormap are changed. Therefore, an explicit
1572
- call `. QuadContourSet.changed()` is needed after modifying the
1579
+ call `` QuadContourSet.changed()` ` is needed after modifying the
1573
1580
colormap. The explicit call can be left out, if a colorbar is
1574
1581
assigned to the `.QuadContourSet` because it internally calls
1575
- `. QuadContourSet.changed()`.
1582
+ `` QuadContourSet.changed()` `.
1576
1583
1577
1584
Example::
1578
1585
0 commit comments