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

colour-science / colour / 9579473519

19 Jun 2024 09:20AM UTC coverage: 2.36% (-97.6%) from 99.978%
9579473519

push

github

KelSolaar
Test only `colour/volume/tests`.

952 of 40339 relevant lines covered (2.36%)

0.02 hits per line

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

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

5
Define the automatic colour conversion graph plotting objects:
6

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

10
from __future__ import annotations
×
11

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

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

27
__all__ = [
×
28
    "plot_automatic_colour_conversion_graph",
29
]
30

31

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

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

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

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

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

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

79
    import networkx as nx
80

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

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

90
    agraph = nx.nx_agraph.to_agraph(cast(nx.DiGraph, colour.graph.CONVERSION_GRAPH))
91

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

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

127
    agraph.draw(filename, prog=prog, args=args)
128

129
    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