Coverage for plotting/corresponding.py: 58%

1"""

2 Corresponding Chromaticities Prediction Plotting

3================================================

4

5 Define the corresponding chromaticities prediction plotting objects.

6

7- :func:`colour.plotting.plot_corresponding_chromaticities_prediction`

8"""

9

10 from __future__ import annotations

11

12 import typing

13

14 if typing.TYPE_CHECKING:

15 from matplotlib.figure import Figure

16 from matplotlib.axes import Axes

17

18 from colour.corresponding import (

19 CorrespondingColourDataset,

20 corresponding_chromaticities_prediction,

21)

22

23 if typing.TYPE_CHECKING:

24 from colour.hints import Any, Dict, Literal, Tuple

25

26 from colour.hints import cast

27 from colour.plotting import (

28 CONSTANTS_COLOUR_STYLE,

29 artist,

30 override_style,

31 plot_chromaticity_diagram_CIE1976UCS,

32 render,

33)

34 from colour.utilities import is_numeric

35

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"

42

43 __all__ = [

44 "plot_corresponding_chromaticities_prediction",

45]

46

47

48@override_style()

49 def 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.

67

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.

78

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.

86

87 Returns

88 -------

89 :class:`tuple`

90 Current figure and axes.

91

92 Examples

93 --------

94 >>> plot_corresponding_chromaticities_prediction(1, "Von Kries")

95 ... # doctest: +ELLIPSIS

96 (<Figure size ... with 1 Axes>, <...Axes...>)

97

98 .. image:: ../_static/Plotting_\

99 Plot_Corresponding_Chromaticities_Prediction.png

100 :align: center

101 :alt: plot_corresponding_chromaticities_prediction

102 """

103

104 if corresponding_chromaticities_prediction_kwargs is None:

105 corresponding_chromaticities_prediction_kwargs = {}

106

107 settings: Dict[str, Any] = {"uniform": True}

108 settings.update(kwargs)

109

110 _figure, axes = artist(**settings)

111

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 )

121

122 settings = {"axes": axes, "title": title}

123 settings.update(kwargs)

124 settings["show"] = False

125

126 plot_chromaticity_diagram_CIE1976UCS(**settings)

127

128 results = corresponding_chromaticities_prediction(

129 experiment, model, **corresponding_chromaticities_prediction_kwargs

130 )

131

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 )

177

178 settings.update(

179 {

180 "show": True,

181 "bounding_box": (-0.1, 0.7, -0.1, 0.7),

182 }

183 )

184 settings.update(kwargs)

185

186 return render(**settings)