Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d492ba4

Browse files
committed
Add test for #rrggbbaa roundtrip; add whatsnew.
1 parent cb3d7c9 commit d492ba4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

doc/users/whats_new/rgba-support.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Improved color conversion API and RGBA support
2+
----------------------------------------------
3+
4+
The :module:`~matplotlib.colors` gained a new color conversion API with
5+
full support for the alpha channel. The main public functions are
6+
:func:`~matplotlib.colors.is_color_like`, :func:`matplotlib.colors.to_rgba`,
7+
:func:`matplotlib.colors.to_rgba_array` and :func:`~matplotlib.colors.to_hex`.
8+
RGBA quadruplets are encoded in hex format as `#rrggbbaa`.
9+
10+
A side benefit is that the Qt options editor now allows setting the alpha
11+
channel of the artists as well.

lib/matplotlib/tests/test_colors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ def test_conversions():
623623
assert_equal(mcolors.to_rgba((1, 1, 1), .5), (1, 1, 1, .5))
624624
# builtin round differs between py2 and py3.
625625
assert_equal(mcolors.to_hex((.7, .7, .7)), "#b2b2b2ff")
626+
# hex roundtrip.
627+
hex_color = "#1234abcd"
628+
assert_equal(mcolors.to_hex(mcolors.to_rgba(hex_color)), hex_color)
626629

627630

628631
if __name__ == '__main__':

0 commit comments

Comments
 (0)