Convert various input in RGB order to normalized RGB matplotlib color tuples, Args: colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs Returns: Union[str, tuple, List[Union[str, tuple]]]: A tuple of 3 normalized floats indicating RGB channels.
(
colors: Union[str, tuple, List[Union[str, tuple]]]
)
| 92 | |
| 93 | |
| 94 | def color_val_matplotlib( |
| 95 | colors: Union[str, tuple, List[Union[str, tuple]]] |
| 96 | ) -> Union[str, tuple, List[Union[str, tuple]]]: |
| 97 | """Convert various input in RGB order to normalized RGB matplotlib color |
| 98 | tuples, |
| 99 | Args: |
| 100 | colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs |
| 101 | Returns: |
| 102 | Union[str, tuple, List[Union[str, tuple]]]: A tuple of 3 normalized |
| 103 | floats indicating RGB channels. |
| 104 | """ |
| 105 | if isinstance(colors, str): |
| 106 | return colors |
| 107 | elif isinstance(colors, tuple): |
| 108 | assert len(colors) == 3 |
| 109 | for channel in colors: |
| 110 | assert 0 <= channel <= 255 |
| 111 | colors = [channel / 255 for channel in colors] |
| 112 | return tuple(colors) |
| 113 | elif isinstance(colors, list): |
| 114 | colors = [ |
| 115 | color_val_matplotlib(color) # type:ignore |
| 116 | for color in colors |
| 117 | ] |
| 118 | return colors |
| 119 | else: |
| 120 | raise TypeError(f'Invalid type for color: {type(colors)}') |
| 121 | |
| 122 | |
| 123 | def color_str2rgb(color: str) -> tuple: |
no outgoing calls
no test coverage detected
searching dependent graphs…