MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / to_hex

Function to_hex

lib/matplotlib/colors.py:555–574  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

553
554
555def 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

Callers 2

color_blockMethod · 0.85
color_blockMethod · 0.85

Calls 2

to_rgbaFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…