def visible_spectrum_plot(cmfs='CIE 1931 2 Degree Standard Observer', out_of_gamut_clipping=True, **kwargs): """ Plots the visible colours spectrum using given standard observer *CIE XYZ* colour matching functions. Parameters ---------- cmfs : unicode, optional Standard observer colour matching functions used for spectrum creation. out_of_gamut_clipping : bool, optional Out of gamut colours will be clipped if *True* otherwise, the colours will be offset by the absolute minimal colour leading to a rendering on gray background, less saturated and smoother. [1]_ \**kwargs : dict, optional Keywords arguments. Returns ------- Figure Current figure or None. Examples -------- >>> visible_spectrum_plot() # doctest: +SKIP """ cmfs = get_cmfs(cmfs) cmfs = cmfs.clone().align(DEFAULT_SPECTRAL_SHAPE) wavelengths = cmfs.shape.range() colours = XYZ_to_sRGB( wavelength_to_XYZ(wavelengths, cmfs), ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['E'], apply_encoding_cctf=False) if not out_of_gamut_clipping: colours += np.abs(np.min(colours)) colours = DEFAULT_PLOTTING_ENCODING_CCTF(normalise_maximum(colours)) settings = { 'title': 'The Visible Spectrum - {0}'.format(cmfs.title), 'x_label': 'Wavelength $\\lambda$ (nm)', 'y_label': False, 'x_tighten': True, 'y_ticker': False } settings.update(kwargs) return colour_parameters_plot([ ColourParameter(x=x[0], RGB=x[1]) for x in tuple(zip(wavelengths, colours)) ], **settings)
def blackbody_colours_plot(shape=SpectralShape(150, 12500, 50), cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots blackbody colours. Parameters ---------- shape : SpectralShape, optional Spectral shape to use as plot boundaries. cmfs : unicode, optional Standard observer colour matching functions. \**kwargs : dict, optional Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> blackbody_colours_plot() # doctest: +SKIP True """ cmfs = get_cmfs(cmfs) colours = [] temperatures = [] for temperature in shape: spd = blackbody_spd(temperature, cmfs.shape) XYZ = spectral_to_XYZ(spd, cmfs) RGB = normalise(XYZ_to_sRGB(XYZ / 100)) colours.append(RGB) temperatures.append(temperature) settings = { 'title': 'Blackbody Colours', 'x_label': 'Temperature K', 'y_label': '', 'x_tighten': True, 'y_ticker': False } settings.update(kwargs) return colour_parameters_plot([ ColourParameter(x=x[0], RGB=x[1]) for x in tuple(zip(temperatures, colours)) ], **settings)
def the_blue_sky_plot(cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots the blue sky. Parameters ---------- cmfs : unicode, optional Standard observer colour matching functions. \**kwargs : dict, optional Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> the_blue_sky_plot() # doctest: +SKIP True """ canvas(**kwargs) cmfs, name = get_cmfs(cmfs), cmfs ASTM_G_173_spd = ASTM_G_173_ETR.clone() rayleigh_spd = rayleigh_scattering_spd() ASTM_G_173_spd.align(rayleigh_spd.shape) spd = rayleigh_spd * ASTM_G_173_spd matplotlib.pyplot.subplots_adjust(hspace=0.4) matplotlib.pyplot.figure(1) matplotlib.pyplot.subplot(211) settings = { 'title': 'The Blue Sky - Synthetic Spectral Power Distribution', 'y_label': u'W / m-2 / nm-1', 'standalone': False } settings.update(kwargs) single_spd_plot(spd, name, **settings) matplotlib.pyplot.subplot(212) settings = { 'title': 'The Blue Sky - Colour', 'x_label': ('The sky is blue because molecules in the atmosphere ' 'scatter shorter wavelengths more than longer ones.\n' 'The synthetic spectral power distribution is computed as ' 'follows: ' '(ASTM G-173 ETR * Standard Air Rayleigh Scattering).'), 'y_label': '', 'aspect': None, 'standalone': False } blue_sky_color = XYZ_to_sRGB(spectral_to_XYZ(spd)) single_colour_plot(ColourParameter('', normalise(blue_sky_color)), **settings) settings = {'standalone': True} settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def colour_checker_plot(colour_checker='ColorChecker 2005', **kwargs): """ Plots given colour checker. Parameters ---------- colour_checker : unicode, optional Color checker name. \**kwargs : dict, optional Keywords arguments. Returns ------- bool Definition success. Raises ------ KeyError If the given colour rendition chart is not found in the factory colour rendition charts. Examples -------- >>> colour_checker_plot() # doctest: +SKIP True """ canvas(**kwargs) colour_checker, name = COLOURCHECKERS.get(colour_checker), colour_checker if colour_checker is None: raise KeyError( ('Colour checker "{0}" not found in ' 'factory colour checkers: "{1}".').format( name, sorted(COLOURCHECKERS.keys()))) _name, data, illuminant = colour_checker colour_parameters = [] for _index, label, x, y, Y in data: XYZ = xyY_to_XYZ((x, y, Y)) RGB = XYZ_to_sRGB(XYZ, illuminant) colour_parameters.append( ColourParameter(label.title(), np.clip(np.ravel(RGB), 0, 1))) background_colour = '0.1' matplotlib.pyplot.gca().patch.set_facecolor(background_colour) width = height = 1.0 spacing = 0.25 across = 6 settings = { 'standalone': False, 'width': width, 'height': height, 'spacing': spacing, 'across': across, 'text_size': 8, 'margins': (-0.125, 0.125, -0.5, 0.125)} settings.update(kwargs) multi_colour_plot(colour_parameters, **settings) text_x = width * (across / 2) + (across * (spacing / 2)) - spacing / 2 text_y = -(len(colour_parameters) / across + spacing / 2) pylab.text(text_x, text_y, '{0} - {1} - Colour Rendition Chart'.format( name, RGB_COLOURSPACES.get('sRGB').name), color='0.95', clip_on=True, ha='center') settings.update({ 'title': name, 'facecolor': background_colour, 'edgecolor': None, 'standalone': True}) boundaries(**settings) decorate(**settings) return display(**settings)
def colour_checker_plot(colour_checker='ColorChecker 2005', **kwargs): """ Plots given colour checker. Parameters ---------- colour_checker : unicode, optional Color checker name. Other Parameters ---------------- \**kwargs : dict, optional {:func:`boundaries`, :func:`canvas`, :func:`decorate`, :func:`display`}, Please refer to the documentation of the previously listed definitions. width : numeric, optional {:func:`multi_colour_plot`}, Colour polygon width. height : numeric, optional {:func:`multi_colour_plot`}, Colour polygon height. spacing : numeric, optional {:func:`multi_colour_plot`}, Colour polygons spacing. across : int, optional {:func:`multi_colour_plot`}, Colour polygons count per row. text_display : bool, optional {:func:`multi_colour_plot`}, Display colour text. text_size : numeric, optional {:func:`multi_colour_plot`}, Colour text size. text_offset : numeric, optional {:func:`multi_colour_plot`}, Colour text offset. Returns ------- Figure Current figure or None. Raises ------ KeyError If the given colour rendition chart is not found in the factory colour rendition charts. Examples -------- >>> colour_checker_plot() # doctest: +SKIP """ canvas(**kwargs) colour_checker, name = COLOURCHECKERS.get(colour_checker), colour_checker if colour_checker is None: raise KeyError(('Colour checker "{0}" not found in ' 'factory colour checkers: "{1}".').format( name, sorted(COLOURCHECKERS.keys()))) _name, data, illuminant = colour_checker colour_parameters = [] for _index, label, xyY in data: XYZ = xyY_to_XYZ(xyY) RGB = XYZ_to_sRGB(XYZ, illuminant) colour_parameters.append( ColourParameter(label.title(), np.clip(np.ravel(RGB), 0, 1))) background_colour = '0.1' width = height = 1.0 spacing = 0.25 across = 6 settings = { 'standalone': False, 'width': width, 'height': height, 'spacing': spacing, 'across': across, 'text_size': 8, 'background_colour': background_colour, 'margins': (-0.125, 0.125, -0.5, 0.125) } settings.update(kwargs) multi_colour_plot(colour_parameters, **settings) text_x = width * (across / 2) + (across * (spacing / 2)) - spacing / 2 text_y = -(len(colour_parameters) / across + spacing / 2) pylab.text( text_x, text_y, '{0} - {1} - Colour Rendition Chart'.format( name, RGB_COLOURSPACES['sRGB'].name), color='0.95', clip_on=True, ha='center') settings.update({ 'title': name, 'facecolor': background_colour, 'edgecolor': None, 'standalone': True }) boundaries(**settings) decorate(**settings) return display(**settings)
def single_spd_plot(spd, cmfs='CIE 1931 2 Degree Standard Observer', out_of_gamut_clipping=True, **kwargs): """ Plots given spectral power distribution. Parameters ---------- spd : SpectralPowerDistribution Spectral power distribution to plot. out_of_gamut_clipping : bool, optional Out of gamut colours will be clipped if *True* otherwise, the colours will be offset by the absolute minimal colour leading to a rendering on gray background, less saturated and smoother. [1]_ cmfs : unicode Standard observer colour matching functions used for spectrum creation. \**kwargs : dict, optional Keywords arguments. Returns ------- Figure Current figure or None. Examples -------- >>> from colour import SpectralPowerDistribution >>> data = {400: 0.0641, 420: 0.0645, 440: 0.0562} >>> spd = SpectralPowerDistribution('Custom', data) >>> single_spd_plot(spd) # doctest: +SKIP """ cmfs = get_cmfs(cmfs) shape = cmfs.shape spd = spd.clone().interpolate(shape, 'Linear') wavelengths = spd.wavelengths values = spd.values y1 = values colours = XYZ_to_sRGB( wavelength_to_XYZ(wavelengths, cmfs), ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['E'], apply_encoding_cctf=False) if not out_of_gamut_clipping: colours += np.abs(np.min(colours)) colours = DEFAULT_PLOTTING_ENCODING_CCTF(normalise_maximum(colours)) settings = { 'title': '{0} - {1}'.format(spd.title, cmfs.title), 'x_label': 'Wavelength $\\lambda$ (nm)', 'y_label': 'Spectral Power Distribution', 'x_tighten': True } settings.update(kwargs) return colour_parameters_plot([ ColourParameter(x=x[0], y1=x[1], RGB=x[2]) for x in tuple(zip(wavelengths, y1, colours)) ], **settings)
def blackbody_spectral_radiance_plot( temperature=3500, cmfs='CIE 1931 2 Degree Standard Observer', blackbody='VY Canis Major', **kwargs): """ Plots given blackbody spectral radiance. Parameters ---------- temperature : numeric, optional Blackbody temperature. cmfs : unicode, optional Standard observer colour matching functions. blackbody : unicode, optional Blackbody name. \**kwargs : dict, optional Keywords arguments. Returns ------- Figure Current figure or None. Examples -------- >>> blackbody_spectral_radiance_plot() # doctest: +SKIP """ canvas(**kwargs) cmfs = get_cmfs(cmfs) matplotlib.pyplot.subplots_adjust(hspace=0.4) spd = blackbody_spd(temperature, cmfs.shape) matplotlib.pyplot.figure(1) matplotlib.pyplot.subplot(211) settings = { 'title': '{0} - Spectral Radiance'.format(blackbody), 'y_label': 'W / (sr m$^2$) / m', 'standalone': False } settings.update(kwargs) single_spd_plot(spd, cmfs.name, **settings) XYZ = spectral_to_XYZ(spd, cmfs) RGB = normalise_maximum(XYZ_to_sRGB(XYZ / 100)) matplotlib.pyplot.subplot(212) settings = { 'title': '{0} - Colour'.format(blackbody), 'x_label': '{0}K'.format(temperature), 'y_label': '', 'aspect': None, 'standalone': False } single_colour_plot(ColourParameter(name='', RGB=RGB), **settings) settings = {'standalone': True} settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def blackbody_colours_plot(shape=SpectralShape(150, 12500, 50), cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots blackbody colours. Parameters ---------- shape : SpectralShape, optional Spectral shape to use as plot boundaries. cmfs : unicode, optional Standard observer colour matching functions. Other Parameters ---------------- \**kwargs : dict, optional {:func:`boundaries`, :func:`canvas`, :func:`decorate`, :func:`display`}, Please refer to the documentation of the previously listed definitions. y0_plot : bool, optional {:func:`colour_parameters_plot`}, Whether to plot *y0* line. y1_plot : bool, optional {:func:`colour_parameters_plot`}, Whether to plot *y1* line. Returns ------- Figure Current figure or None. Examples -------- >>> blackbody_colours_plot() # doctest: +SKIP """ cmfs = get_cmfs(cmfs) colours = [] temperatures = [] for temperature in shape: spd = blackbody_spd(temperature, cmfs.shape) XYZ = spectral_to_XYZ(spd, cmfs) RGB = normalise_maximum(XYZ_to_sRGB(XYZ / 100)) colours.append(RGB) temperatures.append(temperature) settings = { 'title': 'Blackbody Colours', 'x_label': 'Temperature K', 'y_label': '', 'x_tighten': True, 'y_tighten': True, 'y_ticker': False } settings.update(kwargs) return colour_parameters_plot([ ColourParameter(x=x[0], RGB=x[1]) for x in tuple(zip(temperatures, colours)) ], **settings)