diff --git a/colour/colorimetry/lefs.py b/colour/colorimetry/lefs.py index 7b5ffd2cb..d5ee4bfdd 100644 --- a/colour/colorimetry/lefs.py +++ b/colour/colorimetry/lefs.py @@ -101,7 +101,7 @@ def mesopic_weighting_function( mesopic_x_luminance_values = sorted(DATA_MESOPIC_X.keys()) index = mesopic_x_luminance_values.index( - closest(mesopic_x_luminance_values, L_p) # pyright: ignore + closest(mesopic_x_luminance_values, L_p) ) x = DATA_MESOPIC_X[mesopic_x_luminance_values[index]][source][method] diff --git a/colour/io/luts/lut.py b/colour/io/luts/lut.py index 7e6a9294d..d88c5e495 100644 --- a/colour/io/luts/lut.py +++ b/colour/io/luts/lut.py @@ -1493,7 +1493,7 @@ def linear_table( samples = [ np.pad( axis, - (0, np.max(size_array) - len(axis)), + (0, np.max(size_array) - len(axis)), # pyright: ignore mode="constant", constant_values=np.nan, ) diff --git a/colour/io/ocio.py b/colour/io/ocio.py index 9805dffcf..72984cbda 100644 --- a/colour/io/ocio.py +++ b/colour/io/ocio.py @@ -135,9 +135,9 @@ def process_image_OpenColorIO( config = kwargs.get("config") config = ( - ocio.Config.CreateFromEnv() + ocio.Config.CreateFromEnv() # pyright: ignore if config is None - else ocio.Config.CreateFromFile(config) + else ocio.Config.CreateFromFile(config) # pyright: ignore ) a = as_float_array(a) @@ -148,7 +148,9 @@ def process_image_OpenColorIO( processor = config.getProcessor(*args).getDefaultCPUProcessor() - image_desc = ocio.PackedImageDesc(a, width, height, channels) + image_desc = ocio.PackedImageDesc( # pyright: ignore + a, width, height, channels + ) processor.apply(image_desc) diff --git a/colour/plotting/blindness.py b/colour/plotting/blindness.py index 91fc9877d..1a76a9cae 100644 --- a/colour/plotting/blindness.py +++ b/colour/plotting/blindness.py @@ -9,7 +9,8 @@ from __future__ import annotations -import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.algebra import vector_dot from colour.blindness import matrix_cvd_Machado2009 @@ -43,7 +44,7 @@ def plot_cvd_simulation_Machado2009( severity: float = 0.5, M_a: ArrayLike | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Perform colour vision deficiency simulation on given *RGB* colourspace array using *Machado et al. (2009)* model. diff --git a/colour/plotting/characterisation.py b/colour/plotting/characterisation.py index 98960acce..e2354f02e 100644 --- a/colour/plotting/characterisation.py +++ b/colour/plotting/characterisation.py @@ -11,7 +11,8 @@ from __future__ import annotations import numpy as np -import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.hints import Any, Dict, Sequence, Tuple from colour.characterisation import ColourChecker @@ -54,7 +55,7 @@ def plot_single_colour_checker( colour_checker: ColourChecker | str = "ColorChecker24 - After November 2014", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colour checker. @@ -103,7 +104,7 @@ def plot_single_colour_checker( def plot_multi_colour_checkers( colour_checkers: ColourChecker | str | Sequence[ColourChecker | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot and compares given colour checkers. diff --git a/colour/plotting/colorimetry.py b/colour/plotting/colorimetry.py index 0f52accef..02195a60c 100644 --- a/colour/plotting/colorimetry.py +++ b/colour/plotting/colorimetry.py @@ -29,6 +29,8 @@ import matplotlib.pyplot as plt import numpy as np from functools import reduce +from matplotlib.axes import Axes +from matplotlib.figure import Figure from matplotlib.patches import Polygon from colour.algebra import ( @@ -117,7 +119,7 @@ def plot_single_sd( modulate_colours_with_sd_amplitude: bool = False, equalize_sd_amplitude: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distribution. @@ -272,7 +274,7 @@ def plot_multi_sds( | MultiSpectralDistributions, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distributions. @@ -420,7 +422,7 @@ def plot_multi_sds( min(x_limit_min), max(x_limit_max), min(y_limit_min), - max(y_limit_max) * 1.05, # pyright: ignore + max(y_limit_max) * 1.05, ) settings: Dict[str, Any] = { "axes": axes, @@ -442,7 +444,7 @@ def plot_single_cmfs( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colour matching functions. @@ -494,7 +496,7 @@ def plot_multi_cmfs( | str | Sequence[MultiSpectralDistributions | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colour matching functions. @@ -597,7 +599,7 @@ def plot_single_illuminant_sd( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given single illuminant spectral distribution. @@ -661,7 +663,7 @@ def plot_multi_illuminant_sds( | str | Sequence[SpectralDistribution | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given illuminants spectral distributions. @@ -735,7 +737,7 @@ def plot_visible_spectrum( ] = "CIE 1931 2 Degree Standard Observer", out_of_gamut_clipping: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the visible colours spectrum using given standard observer *CIE XYZ* colour matching functions. @@ -812,7 +814,7 @@ def plot_visible_spectrum( @override_style() def plot_single_lightness_function( function: Callable | str, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Lightness* function. @@ -855,7 +857,7 @@ def plot_single_lightness_function( def plot_multi_lightness_functions( functions: Callable | str | Sequence[Callable | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Lightness* functions. @@ -908,7 +910,7 @@ def plot_multi_lightness_functions( @override_style() def plot_single_luminance_function( function: Callable | str, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Luminance* function. @@ -950,7 +952,7 @@ def plot_single_luminance_function( def plot_multi_luminance_functions( functions: Callable | str | Sequence[Callable | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Luminance* functions. @@ -1010,7 +1012,7 @@ def plot_blackbody_spectral_radiance( ] = "CIE 1931 2 Degree Standard Observer", blackbody: str = "VY Canis Major", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given blackbody spectral radiance. @@ -1111,7 +1113,7 @@ def plot_blackbody_colours( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot blackbody colours. diff --git a/colour/plotting/common.py b/colour/plotting/common.py index 0873fc9d6..a2e0eee98 100644 --- a/colour/plotting/common.py +++ b/colour/plotting/common.py @@ -32,12 +32,15 @@ import matplotlib.cm import matplotlib.pyplot as plt import matplotlib.ticker -from mpl_toolkits.mplot3d.axes3d import Axes3D import numpy as np +from cycler import cycler from dataclasses import dataclass, field from functools import partial +from matplotlib.axes import Axes from matplotlib.colors import LinearSegmentedColormap +from matplotlib.figure import Figure from matplotlib.patches import Patch +from mpl_toolkits.mplot3d.axes3d import Axes3D from colour.characterisation import CCS_COLOURCHECKERS, ColourChecker from colour.colorimetry import ( @@ -283,7 +286,7 @@ def colour_style(use_style: bool = True) -> dict: "lines.markersize": constants.geometry.short * 3, "lines.markeredgewidth": constants.geometry.short * 0.75, # Cycle - "axes.prop_cycle": matplotlib.cycler(color=constants.colour.cycle), + "axes.prop_cycle": cycler(color=constants.colour.cycle), } if use_style: @@ -450,11 +453,11 @@ class KwargsArtist(TypedDict): Whether to create the figure with an equal aspect ratio. """ - axes: plt.Axes + axes: Axes uniform: bool -def artist(**kwargs: KwargsArtist | Any) -> Tuple[plt.Figure, plt.Axes]: +def artist(**kwargs: KwargsArtist | Any) -> Tuple[Figure, Axes]: """ Return the current figure and its axes or creates a new one. @@ -480,7 +483,7 @@ def artist(**kwargs: KwargsArtist | Any) -> Tuple[plt.Figure, plt.Axes]: return figure, figure.gca() else: - return cast(plt.Figure, plt.gcf()), cast(plt.Axes, axes) + return plt.gcf(), cast(Axes, axes) class KwargsCamera(TypedDict): @@ -502,14 +505,14 @@ class KwargsCamera(TypedDict): Matplotlib axes aspect. Default is *equal*. """ - figure: plt.Figure - axes: plt.Axes + figure: Figure + axes: Axes azimuth: float | None elevation: float | None camera_aspect: Literal["equal"] | str -def camera(**kwargs: KwargsCamera | Any) -> Tuple[plt.Figure, Axes3D]: +def camera(**kwargs: KwargsCamera | Any) -> Tuple[Figure, Axes3D]: """ Set the camera settings. @@ -525,7 +528,7 @@ def camera(**kwargs: KwargsCamera | Any) -> Tuple[plt.Figure, Axes3D]: Current figure and axes. """ - figure = cast(plt.Figure, kwargs.get("figure", plt.gcf())) + figure = cast(Figure, kwargs.get("figure", plt.gcf())) axes = cast(Axes3D, kwargs.get("axes", plt.gca())) settings = Structure( @@ -587,8 +590,8 @@ class KwargsRender(TypedDict): Whether to display the *Y* axis ticker. Default is *True*. """ - figure: plt.Figure - axes: plt.Axes + figure: Figure + axes: Axes filename: str show: bool aspect: Literal["auto", "equal"] | float @@ -606,7 +609,9 @@ class KwargsRender(TypedDict): y_ticker: bool -def render(**kwargs: KwargsRender | Any) -> Tuple[plt.Figure, plt.Axes]: +def render( + **kwargs: KwargsRender | Any, +) -> Tuple[Figure, Axes] | Tuple[Figure, Axes3D]: """ Render the current figure while adjusting various settings such as the bounding box, the title or background transparency. @@ -623,8 +628,8 @@ def render(**kwargs: KwargsRender | Any) -> Tuple[plt.Figure, plt.Axes]: Current figure and axes. """ - figure = cast(plt.Figure, kwargs.get("figure", plt.gcf())) - axes = cast(plt.Axes, kwargs.get("axes", plt.gca())) + figure = cast(Figure, kwargs.get("figure", plt.gcf())) + axes = cast(Axes, kwargs.get("axes", plt.gca())) kwargs = handle_arguments_deprecation( { @@ -669,9 +674,9 @@ def render(**kwargs: KwargsRender | Any) -> Tuple[plt.Figure, plt.Axes]: if settings.y_label: axes.set_ylabel(settings.y_label) if not settings.x_ticker: - axes.set_xticks([]) # pyright: ignore + axes.set_xticks([]) if not settings.y_ticker: - axes.set_yticks([]) # pyright: ignore + axes.set_yticks([]) if settings.legend: axes.legend(ncol=settings.legend_columns) @@ -697,7 +702,7 @@ def label_rectangles( text_size: float = 10, offset: ArrayLike | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Add labels above given rectangles. @@ -740,13 +745,13 @@ def label_rectangles( x_m, y_m = 0, 0 for rectangle in rectangles: - x_m = max(x_m, rectangle.get_width()) - y_m = max(y_m, rectangle.get_height()) + x_m = max(x_m, rectangle.get_width()) # pyright: ignore + y_m = max(y_m, rectangle.get_height()) # pyright: ignore for i, rectangle in enumerate(rectangles): - x = rectangle.get_x() - height = rectangle.get_height() - width = rectangle.get_width() + x = rectangle.get_x() # pyright: ignore + height = rectangle.get_height() # pyright: ignore + width = rectangle.get_width() # pyright: ignore ha = "center" va = "bottom" axes.text( @@ -764,7 +769,7 @@ def label_rectangles( return figure, axes -def uniform_axes3d(**kwargs: Any) -> Tuple[plt.Figure, plt.Axes]: +def uniform_axes3d(**kwargs: Any) -> Tuple[Figure, Axes]: """ Set equal aspect ratio to given 3d axes. @@ -1108,7 +1113,7 @@ def update_settings_collection( ) def plot_single_colour_swatch( colour_swatch: ArrayLike | ColourSwatch, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colour swatch. @@ -1165,7 +1170,7 @@ def plot_multi_colour_swatches( background_colour: ArrayLike = (1.0, 1.0, 1.0), compare_swatches: Literal["Diagonal", "Stacked"] | str | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colours swatches. @@ -1336,7 +1341,7 @@ def plot_multi_colour_swatches( x_max = x_max * width + x_max * spacing - spacing y_max = offset_Y - axes.patch.set_facecolor(background_colour) + axes.patch.set_facecolor(background_colour) # pyright: ignore if y == 1: bounding_box = [ @@ -1371,7 +1376,7 @@ def plot_single_function( log_y: int | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given function. @@ -1440,7 +1445,7 @@ def plot_multi_functions( log_y: int | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given functions. @@ -1515,8 +1520,8 @@ def plot_multi_functions( plotting_function = axes.loglog - axes.set_xscale("log", base=log_x) # pyright: ignore - axes.set_yscale("log", base=log_y) # pyright: ignore + axes.set_xscale("log", base=log_x) + axes.set_yscale("log", base=log_y) elif log_x is not None: attest(log_x >= 2, "Log base must be equal or greater than 2.") @@ -1563,7 +1568,7 @@ def plot_image( imshow_kwargs: dict | None = None, text_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given image. diff --git a/colour/plotting/corresponding.py b/colour/plotting/corresponding.py index 1049d790c..d112dd062 100644 --- a/colour/plotting/corresponding.py +++ b/colour/plotting/corresponding.py @@ -9,7 +9,8 @@ from __future__ import annotations -import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.corresponding import ( CorrespondingColourDataset, @@ -47,7 +48,7 @@ def plot_corresponding_chromaticities_prediction( | str = "Von Kries", corresponding_chromaticities_prediction_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given chromatic adaptation model corresponding chromaticities prediction. diff --git a/colour/plotting/diagrams.py b/colour/plotting/diagrams.py index 436ee2bea..bee964829 100644 --- a/colour/plotting/diagrams.py +++ b/colour/plotting/diagrams.py @@ -15,9 +15,10 @@ from __future__ import annotations import bisect -import matplotlib.pyplot as plt import numpy as np +from matplotlib.axes import Axes from matplotlib.collections import LineCollection +from matplotlib.figure import Figure from matplotlib.patches import Polygon from colour.algebra import normalise_maximum, normalise_vector @@ -107,7 +108,7 @@ def plot_spectral_locus( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Spectral Locus* according to given method. @@ -291,7 +292,9 @@ def plot_spectral_locus( (sl_ij, spectral_locus_colours), ): line_collection = LineCollection( - np.concatenate([slp_ij[:-1], slp_ij[1:]], axis=1), + np.concatenate( # pyright: ignore + [slp_ij[:-1], slp_ij[1:]], axis=1 + ), colors=slp_colours, alpha=spectral_locus_opacity, zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_scatter, @@ -383,7 +386,7 @@ def plot_chromaticity_diagram_colours( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Chromaticity Diagram* colours according to given method. @@ -520,7 +523,7 @@ def plot_chromaticity_diagram( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Chromaticity Diagram* according to given method. @@ -627,7 +630,7 @@ def plot_chromaticity_diagram_CIE1931( show_diagram_colours: bool = True, show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *CIE 1931 Chromaticity Diagram*. @@ -683,7 +686,7 @@ def plot_chromaticity_diagram_CIE1960UCS( show_diagram_colours: bool = True, show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *CIE 1960 UCS Chromaticity Diagram*. @@ -739,7 +742,7 @@ def plot_chromaticity_diagram_CIE1976UCS( show_diagram_colours: bool = True, show_spectral_locus: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *CIE 1976 UCS Chromaticity Diagram*. @@ -801,7 +804,7 @@ def plot_sds_in_chromaticity_diagram( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distribution chromaticity coordinates into the *Chromaticity Diagram* using given method. @@ -1024,7 +1027,7 @@ def XYZ_to_ij(XYZ: NDArrayFloat) -> NDArrayFloat: XYZ_to_plotting_colourspace(XYZ), 0, 1 ) - ij = XYZ_to_ij(XYZ) + ij = cast(tuple[float, float], XYZ_to_ij(XYZ)) axes.plot(ij[0], ij[1], **plot_settings) @@ -1055,7 +1058,7 @@ def plot_sds_in_chromaticity_diagram_CIE1931( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1931 Chromaticity Diagram*. @@ -1165,7 +1168,7 @@ def plot_sds_in_chromaticity_diagram_CIE1960UCS( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1960 UCS Chromaticity Diagram*. @@ -1276,7 +1279,7 @@ def plot_sds_in_chromaticity_diagram_CIE1976UCS( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given spectral distribution chromaticity coordinates into the *CIE 1976 UCS Chromaticity Diagram*. diff --git a/colour/plotting/models.py b/colour/plotting/models.py index 56c10c646..17ebeb78f 100644 --- a/colour/plotting/models.py +++ b/colour/plotting/models.py @@ -42,9 +42,10 @@ from __future__ import annotations -import matplotlib.pyplot as plt import numpy as np import scipy.optimize +from matplotlib.axes import Axes +from matplotlib.figure import Figure from matplotlib.patches import Ellipse from matplotlib.path import Path @@ -255,7 +256,7 @@ def plot_pointer_gamut( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *Pointer's Gamut* according to given method. @@ -418,7 +419,7 @@ def plot_RGB_colourspaces_in_chromaticity_diagram( chromatically_adapt: bool = False, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspaces in the *Chromaticity Diagram* according to given method. @@ -657,7 +658,7 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( chromatically_adapt: bool = False, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspaces in the *CIE 1931 Chromaticity Diagram*. @@ -752,7 +753,7 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( chromatically_adapt: bool = False, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspaces in the *CIE 1960 UCS Chromaticity Diagram*. @@ -848,7 +849,7 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS( chromatically_adapt: bool = False, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspaces in the *CIE 1976 UCS Chromaticity Diagram*. @@ -938,7 +939,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram( | str = "CIE 1931", scatter_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspace array in the *Chromaticity Diagram* according to given method. @@ -1077,7 +1078,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( ), scatter_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspace array in the *CIE 1931 Chromaticity Diagram*. @@ -1155,7 +1156,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS( ), scatter_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspace array in the *CIE 1960 UCS Chromaticity Diagram*. @@ -1235,7 +1236,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS( ), scatter_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspace array in the *CIE 1976 UCS Chromaticity Diagram*. @@ -1387,7 +1388,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram( chromaticity_diagram_clipping: bool = False, ellipse_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *Chromaticity Diagram* according to given method. @@ -1510,7 +1511,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931( chromaticity_diagram_clipping: bool = False, ellipse_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1931 Chromaticity Diagram*. @@ -1574,7 +1575,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS( chromaticity_diagram_clipping: bool = False, ellipse_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1960 UCS Chromaticity Diagram*. @@ -1639,7 +1640,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS( chromaticity_diagram_clipping: bool = False, ellipse_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *MacAdam (1942) Ellipses (Observer PGN)* in the *CIE 1976 UCS Chromaticity Diagram*. @@ -1699,7 +1700,7 @@ def plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS( @override_style() def plot_single_cctf( cctf: Callable | str, cctf_decoding: bool = False, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colourspace colour component transfer function. @@ -1748,7 +1749,7 @@ def plot_multi_cctfs( cctfs: Callable | str | Sequence[Callable | str], cctf_decoding: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given colour component transfer functions. @@ -1811,7 +1812,7 @@ def plot_constant_hue_loci( scatter_kwargs: dict | None = None, convert_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given constant hue loci colour matches data such as that from :cite:`Hung1995` or :cite:`Ebner1998` that are easily loaded with diff --git a/colour/plotting/notation.py b/colour/plotting/notation.py index bb2d71b88..62312b739 100644 --- a/colour/plotting/notation.py +++ b/colour/plotting/notation.py @@ -10,8 +10,9 @@ from __future__ import annotations -import matplotlib.pyplot as plt import numpy as np +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.hints import Any, Callable, Dict, Sequence, Tuple from colour.notation import MUNSELL_VALUE_METHODS @@ -37,7 +38,7 @@ @override_style() def plot_single_munsell_value_function( function: Callable | str, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Lightness* function. @@ -83,7 +84,7 @@ def plot_single_munsell_value_function( def plot_multi_munsell_value_functions( functions: Callable | str | Sequence[Callable | str], **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *Munsell* value functions. diff --git a/colour/plotting/phenomena.py b/colour/plotting/phenomena.py index 322a03af1..23846a231 100644 --- a/colour/plotting/phenomena.py +++ b/colour/plotting/phenomena.py @@ -11,6 +11,8 @@ from __future__ import annotations import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.algebra import normalise_maximum from colour.colorimetry import ( @@ -65,7 +67,7 @@ def plot_single_sd_rayleigh_scattering( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot a single *Rayleigh* scattering spectral distribution. @@ -138,7 +140,7 @@ def plot_the_blue_sky( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the blue sky. diff --git a/colour/plotting/quality.py b/colour/plotting/quality.py index d5b08fdc8..621be2f1e 100644 --- a/colour/plotting/quality.py +++ b/colour/plotting/quality.py @@ -12,9 +12,10 @@ from __future__ import annotations -import matplotlib.pyplot as plt import numpy as np from itertools import cycle +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.constants import DEFAULT_FLOAT_DTYPE from colour.colorimetry import ( @@ -73,7 +74,7 @@ def plot_colour_quality_bars( hatching: bool | None = None, hatching_repeat: int = 2, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the colour quality data of given illuminants or light sources colour quality specifications. @@ -211,13 +212,11 @@ def plot_colour_quality_bars( ) * bar_width + (count_s * bar_width / 2) - ) # pyright: ignore + ) axes.set_xticklabels( ["Qa"] + [f"Q{index + 1}" for index in range(0, count_Q_as, 1)] - ) # pyright: ignore - axes.set_yticks( - range(0, 100 + y_ticks_interval, y_ticks_interval) - ) # pyright: ignore + ) + axes.set_yticks(range(0, 100 + y_ticks_interval, y_ticks_interval)) aspect = 1 / (120 / (bar_width + len(Q_as) + bar_width * 2)) bounding_box = ( @@ -242,7 +241,7 @@ def plot_colour_quality_bars( @override_style() def plot_single_sd_colour_rendering_index_bars( sd: SpectralDistribution, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Colour Rendering Index* (CRI) of given illuminant or light source spectral distribution. @@ -289,7 +288,7 @@ def plot_multi_sds_colour_rendering_indexes_bars( | SpectralDistribution | MultiSpectralDistributions, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Colour Rendering Index* (CRI) of given illuminants or light sources spectral distributions. @@ -373,7 +372,7 @@ def plot_single_sd_colour_quality_scale_bars( sd: SpectralDistribution, method: Literal["NIST CQS 7.4", "NIST CQS 9.0"] | str = "NIST CQS 9.0", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Colour Quality Scale* (CQS) of given illuminant or light source spectral distribution. @@ -425,7 +424,7 @@ def plot_multi_sds_colour_quality_scales_bars( | MultiSpectralDistributions, method: Literal["NIST CQS 7.4", "NIST CQS 9.0"] | str = "NIST CQS 9.0", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Colour Quality Scale* (CQS) of given illuminants or light sources spectral distributions. diff --git a/colour/plotting/section.py b/colour/plotting/section.py index 61772df7e..d0bbd7f8e 100644 --- a/colour/plotting/section.py +++ b/colour/plotting/section.py @@ -12,9 +12,10 @@ from __future__ import annotations -import matplotlib.pyplot as plt import numpy as np +from matplotlib.axes import Axes from matplotlib.collections import LineCollection +from matplotlib.figure import Figure from matplotlib.patches import Polygon from colour.colorimetry import ( @@ -102,7 +103,7 @@ def plot_hull_section_colours( convert_kwargs: dict | None = None, samples: int = 256, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the section colours of given *trimesh* hull along given axis and origin. @@ -281,7 +282,7 @@ def plot_hull_section_contour( contour_opacity: float = 1, convert_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the section contour of given *trimesh* hull along given axis and origin. @@ -396,7 +397,7 @@ def plot_hull_section_contour( section = np.reshape(section[..., plane], (-1, 1, 2)) line_collection = LineCollection( - np.concatenate([section[:-1], section[1:]], axis=1), + np.concatenate([section[:-1], section[1:]], axis=1), # pyright: ignore colors=contour_colours, alpha=contour_opacity, zorder=CONSTANTS_COLOUR_STYLE.zorder.background_line, @@ -428,7 +429,7 @@ def plot_visible_spectrum_section( show_section_colours: bool = True, show_section_contour: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the visible spectrum volume, i.e. *Ròˆsch-MacAdam* colour solid, section colours along given axis and origin. @@ -578,7 +579,7 @@ def plot_RGB_colourspace_section( show_section_colours: bool = True, show_section_contour: bool = True, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot given *RGB* colourspace section colours along given axis and origin. diff --git a/colour/plotting/temperature.py b/colour/plotting/temperature.py index 58e959de2..71e3f6836 100644 --- a/colour/plotting/temperature.py +++ b/colour/plotting/temperature.py @@ -15,9 +15,10 @@ from __future__ import annotations -import matplotlib.pyplot as plt import numpy as np +from matplotlib.axes import Axes from matplotlib.collections import LineCollection +from matplotlib.figure import Figure from colour.algebra import normalise_maximum from colour.colorimetry import MSDS_CMFS, CCS_ILLUMINANTS @@ -91,7 +92,7 @@ def plot_daylight_locus( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Daylight Locus* according to given method. @@ -201,7 +202,7 @@ def CCT_to_plotting_colourspace(CCT): pl_colours = daylight_locus_colours line_collection = LineCollection( - np.concatenate([ij[:-1], ij[1:]], axis=1), + np.concatenate([ij[:-1], ij[1:]], axis=1), # pyright: ignore colors=pl_colours, alpha=daylight_locus_opacity, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, @@ -224,7 +225,7 @@ def plot_planckian_locus( method: Literal["CIE 1931", "CIE 1960 UCS", "CIE 1976 UCS"] | str = "CIE 1931", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Planckian Locus* according to given method. @@ -356,7 +357,7 @@ def CCT_D_uv_to_plotting_colourspace(CCT_D_uv): pl_colours = planckian_locus_colours line_collection = LineCollection( - np.concatenate([ij[:-1], ij[1:]], axis=1), + np.concatenate([ij[:-1], ij[1:]], axis=1), # pyright: ignore colors=pl_colours, alpha=planckian_locus_opacity, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, @@ -387,15 +388,17 @@ def CCT_D_uv_to_plotting_colourspace(CCT_D_uv): ij = uv_to_ij(CCT_to_uv(CCT_D_uv, "Robertson 1968")) line_collection = LineCollection( - np.concatenate([ij[:-1], ij[1:]], axis=1), + np.concatenate([ij[:-1], ij[1:]], axis=1), # pyright: ignore colors=itl_colours, alpha=planckian_locus_opacity, zorder=CONSTANTS_COLOUR_STYLE.zorder.foreground_line, ) axes.add_collection(line_collection) + + xy = cast(tuple[float, float], (ij[-1, :, 0], ij[-1, :, 1])) axes.annotate( f'{as_int_scalar(label)}{"M" if planckian_locus_use_mireds else "K"}', - xy=(ij[-1, :, 0], ij[-1, :, 1]), + xy=xy, xytext=(0, CONSTANTS_COLOUR_STYLE.geometry.long / 2), textcoords="offset points", size="x-small", @@ -417,7 +420,7 @@ def plot_planckian_locus_in_chromaticity_diagram( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Planckian Locus* and given illuminants in the *Chromaticity Diagram* according to given method. @@ -592,7 +595,7 @@ def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: for i, (illuminant, xy) in enumerate(illuminants_filtered.items()): plot_settings = plot_settings_collection[i] - ij = xy_to_ij(xy) + ij = cast(tuple[float, float], xy_to_ij(xy)) axes.plot(ij[0], ij[1], **plot_settings) @@ -637,7 +640,7 @@ def plot_planckian_locus_in_chromaticity_diagram_CIE1931( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Planckian Locus* and given illuminants in *CIE 1931 Chromaticity Diagram*. @@ -716,7 +719,7 @@ def plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Planckian Locus* and given illuminants in *CIE 1960 UCS Chromaticity Diagram*. @@ -797,7 +800,7 @@ def plot_planckian_locus_in_chromaticity_diagram_CIE1976UCS( annotate_kwargs: dict | List[dict] | None = None, plot_kwargs: dict | List[dict] | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the *Planckian Locus* and given illuminants in *CIE 1976 UCS Chromaticity Diagram*. diff --git a/colour/plotting/tests/test_blindness.py b/colour/plotting/tests/test_blindness.py index c39f48296..167152479 100644 --- a/colour/plotting/tests/test_blindness.py +++ b/colour/plotting/tests/test_blindness.py @@ -3,7 +3,8 @@ import numpy as np import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import plot_cvd_simulation_Machado2009 diff --git a/colour/plotting/tests/test_characterisation.py b/colour/plotting/tests/test_characterisation.py index 3bfd7b087..698ebeba6 100644 --- a/colour/plotting/tests/test_characterisation.py +++ b/colour/plotting/tests/test_characterisation.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.characterisation` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import ( plot_single_colour_checker, diff --git a/colour/plotting/tests/test_colorimetry.py b/colour/plotting/tests/test_colorimetry.py index 9c3bbf6dd..db833f5b7 100644 --- a/colour/plotting/tests/test_colorimetry.py +++ b/colour/plotting/tests/test_colorimetry.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.colorimetry` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import SpectralDistribution from colour.plotting import ( diff --git a/colour/plotting/tests/test_common.py b/colour/plotting/tests/test_common.py index f63b33cf5..1285f21dc 100644 --- a/colour/plotting/tests/test_common.py +++ b/colour/plotting/tests/test_common.py @@ -8,7 +8,8 @@ import tempfile import unittest from functools import partial -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure import colour from colour.colorimetry import SDS_ILLUMINANTS diff --git a/colour/plotting/tests/test_corresponding.py b/colour/plotting/tests/test_corresponding.py index b7196dd25..3562e7f07 100644 --- a/colour/plotting/tests/test_corresponding.py +++ b/colour/plotting/tests/test_corresponding.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.corresponding` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import plot_corresponding_chromaticities_prediction diff --git a/colour/plotting/tests/test_diagrams.py b/colour/plotting/tests/test_diagrams.py index 880508279..54a7dcfad 100644 --- a/colour/plotting/tests/test_diagrams.py +++ b/colour/plotting/tests/test_diagrams.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.diagrams` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import ( MSDS_CMFS, diff --git a/colour/plotting/tests/test_models.py b/colour/plotting/tests/test_models.py index 6f1f5d122..954da5b6a 100644 --- a/colour/plotting/tests/test_models.py +++ b/colour/plotting/tests/test_models.py @@ -3,7 +3,8 @@ import numpy as np import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import ( colourspace_model_axis_reorder, diff --git a/colour/plotting/tests/test_notation.py b/colour/plotting/tests/test_notation.py index 12d95961b..5fecf3eb1 100644 --- a/colour/plotting/tests/test_notation.py +++ b/colour/plotting/tests/test_notation.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.notation` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import ( plot_single_munsell_value_function, diff --git a/colour/plotting/tests/test_phenomena.py b/colour/plotting/tests/test_phenomena.py index d56a487ba..b1e22b255 100644 --- a/colour/plotting/tests/test_phenomena.py +++ b/colour/plotting/tests/test_phenomena.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.phenomena` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import ( plot_single_sd_rayleigh_scattering, diff --git a/colour/plotting/tests/test_quality.py b/colour/plotting/tests/test_quality.py index fb266eab7..0371af415 100644 --- a/colour/plotting/tests/test_quality.py +++ b/colour/plotting/tests/test_quality.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.quality` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import ( SDS_ILLUMINANTS, diff --git a/colour/plotting/tests/test_section.py b/colour/plotting/tests/test_section.py index fb66e88d9..ad9327861 100644 --- a/colour/plotting/tests/test_section.py +++ b/colour/plotting/tests/test_section.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.section` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.geometry import primitive_cube from colour.models import RGB_COLOURSPACE_sRGB, RGB_to_XYZ diff --git a/colour/plotting/tests/test_temperature.py b/colour/plotting/tests/test_temperature.py index c85dd213a..296a7cd59 100644 --- a/colour/plotting/tests/test_temperature.py +++ b/colour/plotting/tests/test_temperature.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.temperature` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import ( plot_planckian_locus_in_chromaticity_diagram_CIE1931, diff --git a/colour/plotting/tests/test_volume.py b/colour/plotting/tests/test_volume.py index 4f2f8abc8..02c9519ff 100644 --- a/colour/plotting/tests/test_volume.py +++ b/colour/plotting/tests/test_volume.py @@ -3,7 +3,8 @@ import numpy as np import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.plotting import plot_RGB_colourspaces_gamuts, plot_RGB_scatter from colour.plotting.volume import nadir_grid, RGB_identity_cube diff --git a/colour/plotting/tm3018/components.py b/colour/plotting/tm3018/components.py index 3fd987fdd..cdfd3936f 100644 --- a/colour/plotting/tm3018/components.py +++ b/colour/plotting/tm3018/components.py @@ -18,7 +18,9 @@ import os import numpy as np -import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure +from matplotlib.patches import Circle from colour.algebra import sdiv, sdiv_mode from colour.colorimetry import sd_to_XYZ @@ -201,7 +203,7 @@ @override_style() def plot_spectra_ANSIIESTM3018( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot a comparison of the spectral distributions of a test emission source and a reference illuminant for *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -259,7 +261,7 @@ def plot_spectra_ANSIIESTM3018( zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_line, ) axes.tick_params(axis="y", which="both", length=0) - axes.set_yticklabels([]) # pyright: ignore + axes.set_yticklabels([]) settings = { "axes": axes, @@ -275,7 +277,7 @@ def plot_spectra_ANSIIESTM3018( def plot_colour_vector_graphic( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot *Color Vector Graphic* according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -348,7 +350,7 @@ def plot_colour_vector_graphic( ) # Circles. - circle = plt.Circle( + circle = Circle( (0, 0), 1, color="black", @@ -358,9 +360,9 @@ def plot_colour_vector_graphic( ) axes.add_artist(circle) for radius in [0.8, 0.9, 1.1, 1.2]: - circle = plt.Circle( + circle = Circle( (0, 0), - radius, # pyright: ignore + radius, color="white", lw=0.75, fill=False, @@ -482,7 +484,7 @@ def plot_16_bin_bars( x_ticker: bool = False, label_orientation: Literal["Horizontal", "Vertical"] | str = "Vertical", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the 16 bin bars for given values according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -536,10 +538,10 @@ def plot_16_bin_bars( ) axes.set_xlim(0.5, bar_count + 0.5) if x_ticker: - axes.set_xticks(np.arange(1, bar_count + 1)) # pyright: ignore + axes.set_xticks(np.arange(1, bar_count + 1)) axes.set_xlabel("Hue-Angle Bin (j)") else: - axes.set_xticks([]) # pyright: ignore + axes.set_xticks([]) label_orientation = label_orientation.lower() value_max = np.max(values) @@ -581,7 +583,7 @@ def plot_local_chroma_shifts( specification: ColourQuality_Specification_ANSIIESTM3018, x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the local chroma shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -626,8 +628,8 @@ def plot_local_chroma_shifts( axes.set_ylabel("Local Chroma Shift ($R_{cs,hj}$)") ticks = np.arange(-40, 41, 10) - axes.set_yticks(ticks) # pyright: ignore - axes.set_yticklabels([f"{value}%" for value in ticks]) # pyright: ignore + axes.set_yticks(ticks) + axes.set_yticklabels([f"{value}%" for value in ticks]) settings = {"show": True} settings.update(kwargs) @@ -639,7 +641,7 @@ def plot_local_hue_shifts( specification: ColourQuality_Specification_ANSIIESTM3018, x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the local hue shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -680,7 +682,7 @@ def plot_local_hue_shifts( specification.R_hs, "{0:.2f}", x_ticker, **settings ) axes.set_ylim(-0.5, 0.5) - axes.set_yticks(np.arange(-0.5, 0.51, 0.1)) # pyright: ignore + axes.set_yticks(np.arange(-0.5, 0.51, 0.1)) axes.set_ylabel("Local Hue Shift ($R_{hs,hj}$)") settings = {"show": True} @@ -693,7 +695,7 @@ def plot_local_colour_fidelities( specification: ColourQuality_Specification_ANSIIESTM3018, x_ticker: bool = False, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the local colour fidelities according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -734,7 +736,7 @@ def plot_local_colour_fidelities( specification.R_fs, "{0:.0f}", x_ticker, "Horizontal", **settings ) axes.set_ylim(0, 100) - axes.set_yticks(np.arange(0, 101, 10)) # pyright: ignore + axes.set_yticks(np.arange(0, 101, 10)) axes.set_ylabel("Local Color Fidelity ($R_{f,hj}$)") settings = {"show": True} @@ -745,7 +747,7 @@ def plot_local_colour_fidelities( def plot_colour_fidelity_indexes( specification: ColourQuality_Specification_ANSIIESTM3018, **kwargs: Any -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Plot the local chroma shifts according to *ANSI/IES TM-30-18 Colour Rendition Report*. @@ -791,15 +793,15 @@ def plot_colour_fidelity_indexes( ) axes.set_xlim(0.5, bar_count + 0.5) axes.set_ylim(0, 100) - axes.set_yticks(np.arange(0, 110, 10)) # pyright: ignore + axes.set_yticks(np.arange(0, 110, 10)) axes.set_ylabel("Color Sample Fidelity ($R_{f,CESi}$)") ticks = list(range(1, bar_count + 1, 1)) - axes.set_xticks(ticks) # pyright: ignore + axes.set_xticks(ticks) labels = [ f"CES{i:02d}" if i % 3 == 1 else "" for i in range(1, bar_count + 1) ] - axes.set_xticklabels(labels, rotation=90) # pyright: ignore + axes.set_xticklabels(labels, rotation=90) return render(**kwargs) diff --git a/colour/plotting/tm3018/report.py b/colour/plotting/tm3018/report.py index 5dbae959b..dbd47afec 100644 --- a/colour/plotting/tm3018/report.py +++ b/colour/plotting/tm3018/report.py @@ -15,6 +15,8 @@ from __future__ import annotations import matplotlib.pyplot as plt +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import SpectralDistribution, sd_to_XYZ from colour.hints import Any, Dict, Literal, Tuple, cast @@ -153,7 +155,7 @@ _VALUE_NOT_APPLICABLE: str = "N/A" -def _plot_report_header(axes: plt.Axes) -> plt.Axes: +def _plot_report_header(axes: Axes) -> Axes: """ Plot the report header, i.e. the title, on given axes. @@ -183,7 +185,7 @@ def _plot_report_header(axes: plt.Axes) -> plt.Axes: return axes -def _plot_report_footer(axes: plt.Axes) -> plt.Axes: +def _plot_report_footer(axes: Axes) -> Axes: """ Plot the report footer on given axes. @@ -228,11 +230,11 @@ def plot_single_sd_colour_rendition_report_full( manufacturer: str | None = None, model: str | None = None, notes: str | None = None, - report_size: tuple = CONSTANT_REPORT_SIZE_FULL, + report_size: tuple[float, float] = CONSTANT_REPORT_SIZE_FULL, report_row_height_ratios: tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_FULL, report_box_padding: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Generate the full *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -540,7 +542,7 @@ def plot_single_sd_colour_rendition_report_full( axes_footer = figure.add_subplot(gridspec_footer[0]) _plot_report_footer(axes_footer) - figure.get_layout_engine().set(**report_box_padding) + figure.get_layout_engine().set(**report_box_padding) # pyright: ignore settings = dict(kwargs) settings["tight_layout"] = False @@ -551,13 +553,13 @@ def plot_single_sd_colour_rendition_report_full( @override_style(**CONSTANTS_REPORT_STYLE) def plot_single_sd_colour_rendition_report_intermediate( sd: SpectralDistribution, - report_size: tuple = CONSTANT_REPORT_SIZE_INTERMEDIATE, + report_size: tuple[float, float] = CONSTANT_REPORT_SIZE_INTERMEDIATE, report_row_height_ratios: tuple = ( CONSTANT_REPORT_ROW_HEIGHT_RATIOS_INTERMEDIATE ), report_box_padding: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Generate the intermediate *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -646,7 +648,7 @@ def plot_single_sd_colour_rendition_report_intermediate( axes_footer = figure.add_subplot(gridspec_footer[0]) _plot_report_footer(axes_footer) - figure.get_layout_engine().set(**report_box_padding) + figure.get_layout_engine().set(**report_box_padding) # pyright: ignore settings = dict(kwargs) settings["tight_layout"] = False @@ -656,11 +658,11 @@ def plot_single_sd_colour_rendition_report_intermediate( def plot_single_sd_colour_rendition_report_simple( sd: SpectralDistribution, - report_size: tuple = CONSTANT_REPORT_SIZE_SIMPLE, + report_size: tuple[float, float] = CONSTANT_REPORT_SIZE_SIMPLE, report_row_height_ratios: tuple = CONSTANT_REPORT_ROW_HEIGHT_RATIOS_SIMPLE, report_box_padding: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Generate the simple *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution. @@ -739,7 +741,7 @@ def plot_single_sd_colour_rendition_report_simple( axes_footer = figure.add_subplot(gridspec_footer[0]) _plot_report_footer(axes_footer) - figure.get_layout_engine().set(**report_box_padding) + figure.get_layout_engine().set(**report_box_padding) # pyright: ignore settings = dict(kwargs) settings["tight_layout"] = False @@ -751,7 +753,7 @@ def plot_single_sd_colour_rendition_report( sd: SpectralDistribution, method: Literal["Full", "Intermediate", "Simple"] | str = "Full", **kwargs: Any, -) -> Tuple[plt.Figure, plt.Axes]: +) -> Tuple[Figure, Axes]: """ Generate the *ANSI/IES TM-30-18 Colour Rendition Report* for given spectral distribution according to given method. diff --git a/colour/plotting/tm3018/tests/test_components.py b/colour/plotting/tm3018/tests/test_components.py index 913af30cd..5f86e13e5 100644 --- a/colour/plotting/tm3018/tests/test_components.py +++ b/colour/plotting/tm3018/tests/test_components.py @@ -4,7 +4,8 @@ from __future__ import annotations import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import SDS_ILLUMINANTS from colour.hints import cast diff --git a/colour/plotting/tm3018/tests/test_report.py b/colour/plotting/tm3018/tests/test_report.py index c4ea8ae96..fd5be2c75 100644 --- a/colour/plotting/tm3018/tests/test_report.py +++ b/colour/plotting/tm3018/tests/test_report.py @@ -2,7 +2,8 @@ """Define the unit tests for the :mod:`colour.plotting.tm3018.report` module.""" import unittest -from matplotlib.pyplot import Axes, Figure +from matplotlib.axes import Axes +from matplotlib.figure import Figure from colour.colorimetry import SDS_ILLUMINANTS from colour.plotting.tm3018.report import ( diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index f949c260d..dc338059c 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -12,6 +12,7 @@ import matplotlib.pyplot as plt import numpy as np +from matplotlib.figure import Figure from mpl_toolkits.mplot3d.axes3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection @@ -438,7 +439,7 @@ def plot_RGB_colourspaces_gamuts( chromatically_adapt: bool = False, convert_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, Axes3D]: +) -> Tuple[Figure, Axes3D]: """ Plot given *RGB* colourspaces gamuts in given reference colourspace. @@ -540,7 +541,7 @@ def plot_RGB_colourspaces_gamuts( settings.update(kwargs) figure = plt.figure() - axes = figure.add_subplot(111, projection="3d") + axes = cast(Axes3D, figure.add_subplot(111, projection="3d")) points = zeros((4, 3)) if show_spectral_locus: @@ -655,8 +656,8 @@ def plot_RGB_colourspaces_gamuts( RGB_e = np.vstack([RGB_ge, RGB_e]) collection = Poly3DCollection(quads) - collection.set_facecolors(RGB_f) - collection.set_edgecolors(RGB_e) + collection.set_facecolors(RGB_f) # pyright: ignore + collection.set_edgecolors(RGB_e) # pyright: ignore axes.add_collection3d(collection) @@ -665,7 +666,7 @@ def plot_RGB_colourspaces_gamuts( ) settings.update(kwargs) - return render(**settings) + return cast(Tuple[Figure, Axes3D], render(**settings)) @override_style() @@ -693,7 +694,7 @@ def plot_RGB_scatter( chromatically_adapt: bool = False, convert_kwargs: dict | None = None, **kwargs: Any, -) -> Tuple[plt.Figure, Axes3D]: +) -> Tuple[Figure, Axes3D]: """ Plot given *RGB* colourspace array in a scatter plot. @@ -806,11 +807,11 @@ def plot_RGB_scatter( points[..., 1], points[..., 2], c=np.reshape(RGB, (-1, 3)), - s=points_size, + s=points_size, # pyright: ignore zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_scatter, ) settings.update({"axes": axes, "show": True}) settings.update(kwargs) - return render(**settings) + return cast(Tuple[Figure, Axes3D], render(**settings)) diff --git a/colour/utilities/array.py b/colour/utilities/array.py index 7893ab062..2b4ba4b0f 100644 --- a/colour/utilities/array.py +++ b/colour/utilities/array.py @@ -2346,7 +2346,7 @@ def row_as_diagonal(a: ArrayLike) -> NDArray: d = np.expand_dims(d, -2) - return np.eye(d.shape[-1]) * d # pyright: ignore + return np.eye(d.shape[-1]) * d def orient( diff --git a/utilities/generate_plots.py b/utilities/generate_plots.py index 020c073b5..133886c72 100755 --- a/utilities/generate_plots.py +++ b/utilities/generate_plots.py @@ -14,7 +14,6 @@ import numpy as np # noqa: E402 import os # noqa: E402 import trimesh # noqa: E402 - import colour # noqa: E402 from colour.characterisation import SDS_COLOURCHECKERS # noqa: E402 from colour.colorimetry import ( # noqa: E402 @@ -30,6 +29,7 @@ sd_to_XYZ, ) from colour.geometry import primitive_cube # noqa: E402 +from colour.hints import cast # noqa: E402 from colour.io import read_image # noqa: E402 from colour.models import ( # noqa: E402 RGB_COLOURSPACE_sRGB, @@ -1222,10 +1222,9 @@ def generate_documentation_plots(output_directory: str): arguments["filename"] = os.path.join( output_directory, "Tutorial_CIE_1931_Chromaticity_Diagram.png" ) - xy = XYZ_to_xy(XYZ) + xy = cast(tuple[float, float], XYZ_to_xy(XYZ)) plot_chromaticity_diagram_CIE1931(standalone=False) - x, y = xy - plt.plot(x, y, "o-", color="white") + plt.plot(xy[0], xy[1], "o-", color="white") # Annotating the plot. plt.annotate( patch_sd.name.title(),