@@ -1773,33 +1773,33 @@ def disconnect(self):
17731773 self .canvas .draw_idle ()
17741774
17751775
1776- def _get_color_list (annotations = False ):
1776+ def _get_color_list (* , remove = None ):
17771777 """Get the current color list from matplotlib rcParams.
17781778
17791779 Parameters
17801780 ----------
1781- annotations : boolean
1782- Has no influence on the function if false. If true, check if color
1783- "red" (#ff0000) is in the cycle and remove it .
1781+ remove : tuple of str | None
1782+ Has no influence on the function if None. Can be a list of colors to
1783+ remove from the list if within 1/255 of the color .
17841784
17851785 Returns
17861786 -------
17871787 colors : list
17881788 """
17891789 from matplotlib import rcParams
1790+ from matplotlib .colors import to_rgba_array
17901791
17911792 color_cycle = rcParams .get ("axes.prop_cycle" )
17921793 colors = color_cycle .by_key ()["color" ]
17931794
1794- # If we want annotations, red is reserved ... remove if present. This
1795- # checks for the reddish color in MPL dark background style, normal style,
1796- # and MPL "red", and defaults to the last of those if none are present
1797- for red in ("#fa8174" , "#d62728" , "#ff0000" ):
1798- if annotations and red in colors :
1799- colors .remove (red )
1800- break
1801-
1802- return (colors , red ) if annotations else colors
1795+ colors_cast = to_rgba_array (colors )[:, :3 ]
1796+ atol = 1.5 / 255.0
1797+ for rem in to_rgba_array (remove or [])[:, :3 ]:
1798+ matches = np .where (np .isclose (colors_cast , rem , atol = atol ).all (- 1 ))[0 ][::- 1 ]
1799+ for idx in matches :
1800+ logger .debug (f"Removing from color cycle: { colors [idx ]} " )
1801+ colors .pop (idx )
1802+ return colors
18031803
18041804
18051805def _merge_annotations (start , stop , description , annotations , current = ()):
0 commit comments