Convert *c* to a hex color. Parameters ---------- c : :mpltype:`color` or `numpy.ma.masked` keep_alpha : bool, default: False If False, use the ``#rrggbb`` format, otherwise use ``#rrggbbaa``. Returns ------- str ``#rrggbb`` or ``#rrggbbaa`` hex color
(c, keep_alpha=False)
| 553 | |
| 554 | |
| 555 | def to_hex(c, keep_alpha=False): |
| 556 | """ |
| 557 | Convert *c* to a hex color. |
| 558 | |
| 559 | Parameters |
| 560 | ---------- |
| 561 | c : :mpltype:`color` or `numpy.ma.masked` |
| 562 | |
| 563 | keep_alpha : bool, default: False |
| 564 | If False, use the ``#rrggbb`` format, otherwise use ``#rrggbbaa``. |
| 565 | |
| 566 | Returns |
| 567 | ------- |
| 568 | str |
| 569 | ``#rrggbb`` or ``#rrggbbaa`` hex color string |
| 570 | """ |
| 571 | c = to_rgba(c) |
| 572 | if not keep_alpha: |
| 573 | c = c[:3] |
| 574 | return "#" + "".join(format(round(val * 255), "02x") for val in c) |
| 575 | |
| 576 | |
| 577 | ### Backwards-compatible color-conversion API |
no test coverage detected
searching dependent graphs…