Coverage for colour/plotting/corresponding.py: 100%
36 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""
2Corresponding Chromaticities Prediction Plotting
3================================================
5Define the corresponding chromaticities prediction plotting objects.
7- :func:`colour.plotting.plot_corresponding_chromaticities_prediction`
8"""
10from __future__ import annotations
12import typing
14if typing.TYPE_CHECKING:
15 from matplotlib.figure import Figure
16 from matplotlib.axes import Axes
18from colour.corresponding import (
19 CorrespondingColourDataset,
20 corresponding_chromaticities_prediction,
21)
23if typing.TYPE_CHECKING:
24 from colour.hints import Any, Dict, Literal, Tuple
26from colour.hints import cast
27from colour.plotting import (
28 CONSTANTS_COLOUR_STYLE,
29 artist,
30 override_style,
31 plot_chromaticity_diagram_CIE1976UCS,
32 render,
33)
34from colour.utilities import is_numeric
36__author__ = "Colour Developers"
37__copyright__ = "Copyright 2013 Colour Developers"
38__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
39__maintainer__ = "Colour Developers"
40__email__ = "colour-developers@colour-science.org"
41__status__ = "Production"
43__all__ = [
44 "plot_corresponding_chromaticities_prediction",
45]
48@override_style()
49def plot_corresponding_chromaticities_prediction(
50 experiment: (Literal[1, 2, 3, 4, 6, 8, 9, 11, 12] | CorrespondingColourDataset) = 1,
51 model: (
52 Literal[
53 "CIE 1994",
54 "CMCCAT2000",
55 "Fairchild 1990",
56 "Von Kries",
57 "Zhai 2018",
58 ]
59 | str
60 ) = "Von Kries",
61 corresponding_chromaticities_prediction_kwargs: dict | None = None,
62 **kwargs: Any,
63) -> Tuple[Figure, Axes]:
64 """
65 Plot the corresponding chromaticities prediction for the specified
66 chromatic adaptation model.
68 Parameters
69 ----------
70 experiment
71 *Breneman (1987)* experiment number or
72 :class:`colour.CorrespondingColourDataset` class instance.
73 model
74 Corresponding chromaticities prediction model name.
75 corresponding_chromaticities_prediction_kwargs
76 Keyword arguments for the
77 :func:`colour.corresponding_chromaticities_prediction` definition.
79 Other Parameters
80 ----------------
81 kwargs
82 {:func:`colour.plotting.artist`,
83 :func:`colour.plotting.diagrams.plot_chromaticity_diagram`,
84 :func:`colour.plotting.render`},
85 See the documentation of the previously listed definitions.
87 Returns
88 -------
89 :class:`tuple`
90 Current figure and axes.
92 Examples
93 --------
94 >>> plot_corresponding_chromaticities_prediction(1, "Von Kries")
95 ... # doctest: +ELLIPSIS
96 (<Figure size ... with 1 Axes>, <...Axes...>)
98 .. image:: ../_static/Plotting_\
99Plot_Corresponding_Chromaticities_Prediction.png
100 :align: center
101 :alt: plot_corresponding_chromaticities_prediction
102 """
104 if corresponding_chromaticities_prediction_kwargs is None:
105 corresponding_chromaticities_prediction_kwargs = {}
107 settings: Dict[str, Any] = {"uniform": True}
108 settings.update(kwargs)
110 _figure, axes = artist(**settings)
112 name = (
113 f"Experiment {experiment}"
114 if is_numeric(experiment)
115 else cast("CorrespondingColourDataset", experiment).name
116 )
117 title = (
118 f"Corresponding Chromaticities Prediction - {model} - {name} - "
119 "CIE 1976 UCS Chromaticity Diagram"
120 )
122 settings = {"axes": axes, "title": title}
123 settings.update(kwargs)
124 settings["show"] = False
126 plot_chromaticity_diagram_CIE1976UCS(**settings)
128 results = corresponding_chromaticities_prediction(
129 experiment, model, **corresponding_chromaticities_prediction_kwargs
130 )
132 for result in results:
133 _name, uv_t, uv_m, uv_p = result.values
134 axes.arrow(
135 uv_t[0],
136 uv_t[1],
137 uv_p[0] - uv_t[0] - 0.1 * (uv_p[0] - uv_t[0]),
138 uv_p[1] - uv_t[1] - 0.1 * (uv_p[1] - uv_t[1]),
139 color=CONSTANTS_COLOUR_STYLE.colour.dark,
140 head_width=0.005,
141 head_length=0.005,
142 zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_annotation,
143 )
144 axes.plot(
145 uv_t[0],
146 uv_t[1],
147 "o",
148 color=CONSTANTS_COLOUR_STYLE.colour.brightest,
149 markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark,
150 markersize=(
151 CONSTANTS_COLOUR_STYLE.geometry.short * 6
152 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75
153 ),
154 markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75,
155 zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line,
156 )
157 axes.plot(
158 uv_m[0],
159 uv_m[1],
160 "^",
161 color=CONSTANTS_COLOUR_STYLE.colour.brightest,
162 markeredgecolor=CONSTANTS_COLOUR_STYLE.colour.dark,
163 markersize=(
164 CONSTANTS_COLOUR_STYLE.geometry.short * 6
165 + CONSTANTS_COLOUR_STYLE.geometry.short * 0.75
166 ),
167 markeredgewidth=CONSTANTS_COLOUR_STYLE.geometry.short * 0.75,
168 zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line,
169 )
170 axes.plot(
171 uv_p[0],
172 uv_p[1],
173 "^",
174 color=CONSTANTS_COLOUR_STYLE.colour.dark,
175 zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line,
176 )
178 settings.update(
179 {
180 "show": True,
181 "bounding_box": (-0.1, 0.7, -0.1, 0.7),
182 }
183 )
184 settings.update(kwargs)
186 return render(**settings)