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