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

Function test_color_sequences

lib/matplotlib/tests/test_colors.py:1699–1737  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1697
1698
1699def test_color_sequences():
1700 # basic access
1701 assert plt.color_sequences is matplotlib.color_sequences # same registry
1702 assert list(plt.color_sequences) == [
1703 'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
1704 'Accent', 'okabe_ito', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6',
1705 'petroff8', 'petroff10']
1706 assert len(plt.color_sequences['tab10']) == 10
1707 assert len(plt.color_sequences['tab20']) == 20
1708
1709 tab_colors = [
1710 'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple',
1711 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan']
1712 for seq_color, tab_color in zip(plt.color_sequences['tab10'], tab_colors):
1713 assert mcolors.same_color(seq_color, tab_color)
1714
1715 # registering
1716 with pytest.raises(ValueError, match="reserved name"):
1717 plt.color_sequences.register('tab10', ['r', 'g', 'b'])
1718 with pytest.raises(ValueError, match="not a valid color specification"):
1719 plt.color_sequences.register('invalid', ['not a color'])
1720
1721 rgb_colors = ['r', 'g', 'b']
1722 plt.color_sequences.register('rgb', rgb_colors)
1723 assert plt.color_sequences['rgb'] == ['r', 'g', 'b']
1724 # should not affect the registered sequence because input is copied
1725 rgb_colors.append('c')
1726 assert plt.color_sequences['rgb'] == ['r', 'g', 'b']
1727 # should not affect the registered sequence because returned list is a copy
1728 plt.color_sequences['rgb'].append('c')
1729 assert plt.color_sequences['rgb'] == ['r', 'g', 'b']
1730
1731 # unregister
1732 plt.color_sequences.unregister('rgb')
1733 with pytest.raises(KeyError):
1734 plt.color_sequences['rgb'] # rgb is gone
1735 plt.color_sequences.unregister('rgb') # multiple unregisters are ok
1736 with pytest.raises(ValueError, match="Cannot unregister builtin"):
1737 plt.color_sequences.unregister('tab10')
1738
1739
1740def test_cm_set_cmap_error():

Callers

nothing calls this directly

Calls 2

registerMethod · 0.45
unregisterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…