• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

colour-science / colour / 4382699875

pending completion
4382699875

push

github-actions

Thomas Mansencal
Merge branch 'feature/v0.4.3' into develop

7 of 7 new or added lines in 1 file covered. (100.0%)

38585 of 38659 relevant lines covered (99.81%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.72
/colour/plotting/graph.py
1
"""
2
Automatic Colour Conversion Graph Plotting
3
==========================================
4

5
Defines the automatic colour conversion graph plotting objects:
6

7
-   :func:`colour.plotting.plot_automatic_colour_conversion_graph`
8
"""
9

10
from __future__ import annotations
1✔
11

12
import colour
1✔
13
from colour.graph import (
1✔
14
    CONVERSION_GRAPH_NODE_LABELS,
15
    describe_conversion_path,
16
)
17
from colour.hints import Literal
1✔
18
from colour.utilities import required, validate_method
1✔
19

20
__author__ = "Colour Developers"
1✔
21
__copyright__ = "Copyright 2013 Colour Developers"
1✔
22
__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause"
1✔
23
__maintainer__ = "Colour Developers"
1✔
24
__email__ = "colour-developers@colour-science.org"
1✔
25
__status__ = "Production"
1✔
26

27
__all__ = [
1✔
28
    "plot_automatic_colour_conversion_graph",
29
]
30

31

32
@required("Graphviz")
1✔
33
@required("NetworkX")
1✔
34
def plot_automatic_colour_conversion_graph(
1✔
35
    filename: str,
36
    prog: Literal["circo", "dot", "fdp", "neato", "nop", "twopi"]
37
    | str = "fdp",
38
    args: str = "",
39
) -> AGraph:  # pyright: ignore  # noqa: F821
40
    """
41
    Plot *Colour* automatic colour conversion graph using
42
    `Graphviz <https://www.graphviz.org/>`__ and
43
    `pyraphviz <https://pygraphviz.github.io>`__.
44

45
    Parameters
46
    ----------
47
    filename
48
        Filename to use to save the image.
49
    prog
50
        *Graphviz* layout method.
51
    args
52
         Additional arguments for *Graphviz*.
53

54
    Returns
55
    -------
56
    :class:`AGraph`
57
        *Pyraphviz* graph.
58

59
    Notes
60
    -----
61
    -   This definition does not directly plot the *Colour* automatic colour
62
        conversion graph but instead write it to an image.
63

64
    Examples
65
    --------
66
    >>> import tempfile
67
    >>> import colour
68
    >>> from colour import read_image
69
    >>> from colour.plotting import plot_image
70
    >>> filename = "{0}.png".format(tempfile.mkstemp()[-1])
71
    >>> _ = plot_automatic_colour_conversion_graph(filename, "dot")
72
    ... # doctest: +SKIP
73
    >>> plot_image(read_image(filename))  # doctest: +SKIP
74

75
    .. image:: ../_static/Plotting_Plot_Colour_Automatic_Conversion_Graph.png
76
        :align: center
77
        :alt: plot_automatic_colour_conversion_graph
78
    """
79

80
    import networkx as nx
×
81

82
    prog = validate_method(
×
83
        prog,
84
        ["circo", "dot", "fdp", "neato", "nop", "twopi"],
85
        '"{0}" program is invalid, it must be one of {1}!',
86
    )
87

88
    # TODO: Investigate API to trigger the conversion graph build.
89
    describe_conversion_path("RGB", "RGB", print_callable=lambda x: x)
×
90

91
    agraph = nx.nx_agraph.to_agraph(colour.graph.CONVERSION_GRAPH)
×
92

93
    for node in agraph.nodes():
×
94
        node.attr.update(label=CONVERSION_GRAPH_NODE_LABELS[node.name])
×
95

96
    agraph.node_attr.update(
×
97
        style="filled",
98
        shape="circle",
99
        color="#2196F3FF",
100
        fillcolor="#2196F370",
101
        fontname="Helvetica",
102
        fontcolor="#263238",
103
    )
104
    agraph.edge_attr.update(color="#26323870")
×
105
    for node in ("CIE XYZ", "RGB", "Spectral Distribution"):
×
106
        agraph.get_node(node.lower()).attr.update(
×
107
            shape="doublecircle",
108
            color="#673AB7FF",
109
            fillcolor="#673AB770",
110
            fontsize=30,
111
        )
112
    for node in (
×
113
        "ATD95",
114
        "CAM16",
115
        "CIECAM02",
116
        "Hellwig 2022",
117
        "Hunt",
118
        "Kim 2009",
119
        "LLAB",
120
        "Nayatani95",
121
        "RLAB",
122
        "ZCAM",
123
    ):
124
        agraph.get_node(node.lower()).attr.update(
×
125
            color="#00BCD4FF", fillcolor="#00BCD470"
126
        )
127

128
    agraph.draw(filename, prog=prog, args=args)
×
129

130
    return agraph
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc