def single_spd_plot(spd, cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots given spectral power distribution. Parameters ---------- spd : SpectralPowerDistribution, optional Spectral power distribution to plot. cmfs : unicode Standard observer colour matching functions used for spectrum creation. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. 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 True """ cmfs, name = get_cmfs(cmfs), cmfs shape = cmfs.shape spd = spd.clone().interpolate(shape) wavelengths = shape.range() colours = [] y1 = [] for wavelength, value in spd: XYZ = wavelength_to_XYZ(wavelength, cmfs) colours.append(XYZ_to_sRGB(XYZ)) y1.append(value) colours = normalise(colours) settings = { 'title': '"{0}" - {1}'.format(spd.name, cmfs.name), 'x_label': u'Wavelength λ (nm)', 'y_label': 'Spectral Power Distribution', 'x_tighten': True, 'x_ticker': True, 'y_ticker': True } settings.update(kwargs) return colour_parameters_plot([ colour_parameter(x=x[0], y1=x[1], RGB=x[2]) for x in tuple(zip(wavelengths, y1, colours)) ], **settings)
def single_spd_plot(spd, cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots given spectral power distribution. Parameters ---------- spd : SpectralPowerDistribution Spectral power distribution to plot. cmfs : unicode Standard observer colour matching functions used for spectrum creation. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. 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 True """ cmfs = get_cmfs(cmfs) shape = cmfs.shape spd = spd.clone().interpolate(shape, 'Linear') wavelengths = spd.wavelengths colours = [] y1 = [] for wavelength, value in spd: XYZ = wavelength_to_XYZ(wavelength, cmfs) colours.append(XYZ_to_sRGB(XYZ)) y1.append(value) colours = normalise(colours) settings = { 'title': '{0} - {1}'.format(spd.title, cmfs.title), 'x_label': 'Wavelength $\\lambda$ (nm)', 'y_label': 'Spectral Power Distribution', 'x_tighten': True, 'x_ticker': True, 'y_ticker': True} settings.update(kwargs) return colour_parameters_plot( [colour_parameter(x=x[0], y1=x[1], RGB=x[2]) for x in tuple(zip(wavelengths, y1, 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 : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> blackbody_colours_plot() # doctest: +SKIP True """ cmfs, name = get_cmfs(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, 'x_ticker': True, 'y_ticker': False } settings.update(kwargs) return colour_parameters_plot([ colour_parameter(x=x[0], RGB=x[1]) for x in tuple(zip(temperatures, 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 : \*\* 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, 'x_ticker': True, 'y_ticker': False} settings.update(kwargs) return colour_parameters_plot([colour_parameter(x=x[0], RGB=x[1]) for x in tuple(zip(temperatures, colours))], **settings)
def test_normalise(self): """ Tests :func:`colour.algebra.common.normalise` definition. """ np.testing.assert_almost_equal( normalise(np.array([0.1151847498, 0.1008, 0.0508937252])), np.array([1., 0.87511585, 0.4418443]), decimal=7) np.testing.assert_almost_equal( normalise(np.array([0.1151847498, 0.1008, 0.0508937252]), factor=10), np.array([10., 8.75115848, 4.418443]), decimal=7) np.testing.assert_almost_equal( normalise(np.array([-0.1151847498, -0.1008, 0.0508937252])), np.array([0., 0., 1.]), decimal=7) np.testing.assert_almost_equal( normalise(np.array([-0.1151847498, -0.1008, 0.0508937252]), clip=False), np.array([-2.26324069, -1.9805978, 1.]), decimal=7)
def test_normalise(self): """ Tests :func:`colour.algebra.common.normalise` definition. """ np.testing.assert_almost_equal(normalise( np.array([0.1151847498, 0.1008, 0.0508937252])), np.array([1., 0.87511585, 0.4418443]), decimal=7) np.testing.assert_almost_equal(normalise(np.array( [0.1151847498, 0.1008, 0.0508937252]), factor=10), np.array([10., 8.75115848, 4.418443]), decimal=7) np.testing.assert_almost_equal(normalise( np.array([-0.1151847498, -0.1008, 0.0508937252])), np.array([0., 0., 1.]), decimal=7) np.testing.assert_almost_equal(normalise(np.array( [-0.1151847498, -0.1008, 0.0508937252]), clip=False), np.array([-2.26324069, -1.9805978, 1.]), decimal=7)
def colour_rendering_index_bars_plot(illuminant, **kwargs): """ Plots the *colour rendering index* of given illuminant. Parameters ---------- illuminant : SpectralPowerDistribution Illuminant to plot the *colour rendering index*. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> from colour import ILLUMINANTS_RELATIVE_SPDS >>> illuminant = ILLUMINANTS_RELATIVE_SPDS.get('F2') >>> colour_rendering_index_bars_plot(illuminant) # doctest: +SKIP True """ figure, axis = matplotlib.pyplot.subplots() cri, colour_rendering_indexes, additional_data = \ colour_rendering_index(illuminant, additional_data=True) colours = ([[1] * 3] + [normalise(XYZ_to_sRGB(x.XYZ / 100)) for x in additional_data[0]]) x, y = tuple(zip(*sorted(colour_rendering_indexes.items(), key=lambda x: x[0]))) x, y = np.array([0] + list(x)), np.array( [cri] + list(y)) positive = True if np.sign(min(y)) in (0, 1) else False width = 0.5 bars = pylab.bar(x, y, color=colours, width=width) y_ticks_steps = 10 pylab.yticks(range(0 if positive else -100, 100 + y_ticks_steps, y_ticks_steps)) pylab.xticks(x + width / 2, ['Ra'] + ['R{0}'.format(index) for index in x[1:]]) def label_bars(bars): """ Add labels above given bars. """ for bar in bars: y = bar.get_y() height = bar.get_height() value = height if np.sign(y) in (0, 1) else -height axis.text(bar.get_x() + bar.get_width() / 2, 0.025 * height + height + y, '{0:.1f}'.format(value), ha='center', va='bottom') label_bars(bars) settings = { 'title': 'Colour Rendering Index - {0}'.format(illuminant.name), 'grid': True, 'x_tighten': True, 'y_tighten': True, 'limits': [-width, 14 + width * 2, -10 if positive else -110, 110]} settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**settings)
def CIE_1931_chromaticity_diagram_colours_plot( surface=1.25, spacing=0.00075, cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots the *CIE 1931 Chromaticity Diagram* colours. Parameters ---------- surface : numeric, optional Generated markers surface. spacing : numeric, optional Spacing between markers. cmfs : unicode, optional Standard observer colour matching functions used for diagram bounds. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> CIE_1931_chromaticity_diagram_colours_plot() # doctest: +SKIP True """ cmfs, name = get_cmfs(cmfs), cmfs illuminant = ILLUMINANTS.get( 'CIE 1931 2 Degree Standard Observer').get('E') XYZs = [value for key, value in cmfs] x, y = tuple(zip(*([XYZ_to_xy(x) for x in XYZs]))) path = matplotlib.path.Path(tuple(zip(x, y))) x_dot, y_dot, colours = [], [], [] for i in np.arange(0, 1, spacing): for j in np.arange(0, 1, spacing): if path.contains_path(matplotlib.path.Path([[i, j], [i, j]])): x_dot.append(i) y_dot.append(j) XYZ = xy_to_XYZ((i, j)) RGB = normalise(XYZ_to_sRGB(XYZ, illuminant)) colours.append(RGB) pylab.scatter(x_dot, y_dot, color=colours, s=surface) settings = {'no_ticks': True, 'bounding_box': [0, 1, 0, 1], 'bbox_inches': 'tight', 'pad_inches': 0} settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**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 : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> blackbody_spectral_radiance_plot() # doctest: +SKIP True """ 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(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(colour_parameter(name='', RGB=RGB), **settings) settings = { 'standalone': True} settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def multi_spd_plot(spds, cmfs='CIE 1931 2 Degree Standard Observer', use_spds_colours=False, normalise_spds_colours=False, **kwargs): """ Plots given spectral power distributions. Parameters ---------- spds : list Spectral power distributions to plot. cmfs : unicode, optional Standard observer colour matching functions used for spectrum creation. use_spds_colours : bool, optional Use spectral power distributions colours. normalise_spds_colours : bool Should spectral power distributions colours normalised. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> from colour import SpectralPowerDistribution >>> data1 = {400: 0.0641, 420: 0.0645, 440: 0.0562} >>> data2 = {400: 0.134, 420: 0.789, 440: 1.289} >>> spd1 = SpectralPowerDistribution('Custom1', data1) >>> spd2 = SpectralPowerDistribution('Custom2', data2) >>> multi_spd_plot([spd1, spd2]) # doctest: +SKIP True """ canvas(**kwargs) cmfs = get_cmfs(cmfs) if use_spds_colours: illuminant = ILLUMINANTS_RELATIVE_SPDS.get('D65') x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], [] for spd in spds: wavelengths, values = tuple(zip(*spd.items)) shape = spd.shape x_limit_min.append(shape.start) x_limit_max.append(shape.end) y_limit_min.append(min(values)) y_limit_max.append(max(values)) matplotlib.pyplot.rc("axes", color_cycle=["r", "g", "b", "y"]) if use_spds_colours: XYZ = spectral_to_XYZ(spd, cmfs, illuminant) / 100 if normalise_spds_colours: XYZ = normalise(XYZ, clip=False) RGB = np.clip(XYZ_to_sRGB(XYZ), 0, 1) pylab.plot(wavelengths, values, color=RGB, label=spd.title, linewidth=2) else: pylab.plot(wavelengths, values, label=spd.title, linewidth=2) settings = { 'x_label': 'Wavelength $\\lambda$ (nm)', 'y_label': 'Spectral Power Distribution', 'x_tighten': True, 'legend': True, 'legend_location': 'upper left', 'x_ticker': True, 'y_ticker': True, 'limits': [min(x_limit_min), max(x_limit_max), min(y_limit_min), max(y_limit_max)]} settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def colour_rendering_index_bars_plot(illuminant, **kwargs): """ Plots the *colour rendering index* of given illuminant. Parameters ---------- illuminant : SpectralPowerDistribution Illuminant to plot the *colour rendering index*. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> from colour import ILLUMINANTS_RELATIVE_SPDS >>> illuminant = ILLUMINANTS_RELATIVE_SPDS.get('F2') >>> colour_rendering_index_bars_plot(illuminant) # doctest: +SKIP True """ figure, axis = matplotlib.pyplot.subplots() cri, colour_rendering_indexes, additional_data = \ colour_rendering_index(illuminant, additional_data=True) colours = ( [[1] * 3] + [normalise(XYZ_to_sRGB(x.XYZ / 100)) for x in additional_data[0]]) x, y = tuple( zip(*sorted(colour_rendering_indexes.items(), key=lambda x: x[0]))) x, y = np.array([0] + list(x)), np.array([cri] + list(y)) positive = True if np.sign(min(y)) in (0, 1) else False width = 0.5 bars = pylab.bar(x, y, color=colours, width=width) y_ticks_steps = 10 pylab.yticks( range(0 if positive else -100, 100 + y_ticks_steps, y_ticks_steps)) pylab.xticks(x + width / 2, ['Ra'] + ['R{0}'.format(index) for index in x[1:]]) def label_bars(bars): """ Add labels above given bars. """ for bar in bars: y = bar.get_y() height = bar.get_height() value = height if np.sign(y) in (0, 1) else -height axis.text(bar.get_x() + bar.get_width() / 2, 0.025 * height + height + y, '{0:.1f}'.format(value), ha='center', va='bottom') label_bars(bars) settings = { 'title': 'Colour Rendering Index - {0}'.format(illuminant.name), 'grid': True, 'x_tighten': True, 'y_tighten': True, 'limits': [-width, 14 + width * 2, -10 if positive else -110, 110] } settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**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 : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> the_blue_sky_plot() # doctest: +SKIP True """ 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(colour_parameter('', normalise(blue_sky_color)), **settings) settings = {'standalone': True} settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**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 : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> blackbody_spectral_radiance_plot() # doctest: +SKIP True """ cmfs, name = get_cmfs(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': u'W / (sr m²) / m', 'standalone': False } settings.update(kwargs) single_spd_plot(spd, name, **settings) XYZ = spectral_to_XYZ(spd, cmfs) RGB = normalise(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(colour_parameter(name='', RGB=RGB), **settings) settings = {'standalone': True} settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**settings)
def multi_spd_plot(spds, cmfs='CIE 1931 2 Degree Standard Observer', use_spds_colours=False, normalise_spds_colours=False, **kwargs): """ Plots given spectral power distributions. Parameters ---------- spds : list, optional Spectral power distributions to plot. cmfs : unicode, optional Standard observer colour matching functions used for spectrum creation. use_spds_colours : bool, optional Use spectral power distributions colours. normalise_spds_colours : bool Should spectral power distributions colours normalised. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> from colour import SpectralPowerDistribution >>> data1 = {400: 0.0641, 420: 0.0645, 440: 0.0562} >>> data2 = {400: 0.134, 420: 0.789, 440: 1.289} >>> spd1 = SpectralPowerDistribution('Custom1', data1) >>> spd2 = SpectralPowerDistribution('Custom2', data2) >>> multi_spd_plot([spd1, spd2]) # doctest: +SKIP True """ cmfs, name = get_cmfs(cmfs), cmfs if use_spds_colours: illuminant = ILLUMINANTS_RELATIVE_SPDS.get('D65') x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], [] for spd in spds: wavelengths, values = tuple(zip(*[(key, value) for key, value in spd])) shape = spd.shape x_limit_min.append(shape.start) x_limit_max.append(shape.end) y_limit_min.append(min(values)) y_limit_max.append(max(values)) matplotlib.pyplot.rc("axes", color_cycle=["r", "g", "b", "y"]) if use_spds_colours: XYZ = spectral_to_XYZ(spd, cmfs, illuminant) / 100 if normalise_spds_colours: XYZ = normalise(XYZ, clip=False) RGB = np.clip(XYZ_to_sRGB(XYZ), 0, 1) pylab.plot(wavelengths, values, color=RGB, label=spd.name, linewidth=2) else: pylab.plot(wavelengths, values, label=spd.name, linewidth=2) settings = { 'x_label': u'Wavelength λ (nm)', 'y_label': 'Spectral Power Distribution', 'x_tighten': True, 'legend': True, 'legend_location': 'upper left', 'x_ticker': True, 'y_ticker': True, 'limits': [ min(x_limit_min), max(x_limit_max), min(y_limit_min), max(y_limit_max) ] } settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**settings)
def CIE_1931_chromaticity_diagram_colours_plot( surface=1.25, spacing=0.00075, cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots the *CIE 1931 Chromaticity Diagram* colours. Parameters ---------- surface : numeric, optional Generated markers surface. spacing : numeric, optional Spacing between markers. cmfs : unicode, optional Standard observer colour matching functions used for diagram bounds. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> CIE_1931_chromaticity_diagram_colours_plot() # doctest: +SKIP True """ cmfs, name = get_cmfs(cmfs), cmfs illuminant = ILLUMINANTS.get('CIE 1931 2 Degree Standard Observer').get( 'E') XYZs = [value for key, value in cmfs] x, y = tuple(zip(*([XYZ_to_xy(x) for x in XYZs]))) path = matplotlib.path.Path(tuple(zip(x, y))) x_dot, y_dot, colours = [], [], [] for i in np.arange(0, 1, spacing): for j in np.arange(0, 1, spacing): if path.contains_path(matplotlib.path.Path([[i, j], [i, j]])): x_dot.append(i) y_dot.append(j) XYZ = xy_to_XYZ((i, j)) RGB = normalise(XYZ_to_sRGB(XYZ, illuminant)) colours.append(RGB) pylab.scatter(x_dot, y_dot, color=colours, s=surface) settings = { 'no_ticks': True, 'bounding_box': [0, 1, 0, 1], 'bbox_inches': 'tight', 'pad_inches': 0 } settings.update(kwargs) bounding_box(**settings) aspect(**settings) return display(**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 : \*\* 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(colour_parameter('', normalise(blue_sky_color)), **settings) settings = {'standalone': True} settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def CIE_1976_UCS_chromaticity_diagram_colours_plot( surface=1.25, spacing=0.00075, cmfs='CIE 1931 2 Degree Standard Observer', **kwargs): """ Plots the *CIE 1976 UCS Chromaticity Diagram* colours. Parameters ---------- surface : numeric, optional Generated markers surface. spacing : numeric, optional Spacing between markers. cmfs : unicode, optional Standard observer colour matching functions used for diagram bounds. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> CIE_1976_UCS_chromaticity_diagram_colours_plot() # doctest: +SKIP True """ settings = {'figure_size': (32, 32)} settings.update(kwargs) canvas(**settings) cmfs = get_cmfs(cmfs) illuminant = ILLUMINANTS.get( 'CIE 1931 2 Degree Standard Observer').get('D50') uv = np.array([Luv_to_uv(XYZ_to_Luv(XYZ, illuminant)) for XYZ in cmfs.values]) path = matplotlib.path.Path(uv) x_dot, y_dot, colours = [], [], [] for i in np.arange(0, 1, spacing): for j in np.arange(0, 1, spacing): if path.contains_path(matplotlib.path.Path([[i, j], [i, j]])): x_dot.append(i) y_dot.append(j) XYZ = xy_to_XYZ(Luv_uv_to_xy((i, j))) RGB = normalise(XYZ_to_sRGB(XYZ, illuminant)) colours.append(RGB) pylab.scatter(x_dot, y_dot, color=colours, s=surface) settings.update({ 'no_ticks': True, 'bounding_box': [0, 1, 0, 1], 'bbox_inches': 'tight', 'pad_inches': 0}) settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)
def colour_quality_bars_plot(specification, **kwargs): """ Plots the colour quality data of given illuminant or light source colour quality specification. Parameters ---------- specification : CRI_Specification or VS_ColourQualityScaleData Illuminant or light source specification colour quality specification. \*\*kwargs : \*\* Keywords arguments. Returns ------- bool Definition success. Examples -------- >>> from colour import ILLUMINANTS_RELATIVE_SPDS >>> illuminant = ILLUMINANTS_RELATIVE_SPDS.get('F2') >>> colour_quality_bars_plot(illuminant) # doctest: +SKIP True """ settings = {'figure_size': (DEFAULT_FIGURE_WIDTH, DEFAULT_FIGURE_WIDTH)} settings.update(kwargs) canvas(**settings) axis = matplotlib.pyplot.gca() Q_a, Q_as, colorimetry_data = (specification.Q_a, specification.Q_as, specification.colorimetry_data) colours = ([[1] * 3] + [normalise(XYZ_to_sRGB(x.XYZ / 100)) for x in colorimetry_data[0]]) x, y = tuple(zip(*[(x[0], x[1].Q_a) for x in sorted(Q_as.items(), key=lambda x: x[0])])) x, y = np.array([0] + list(x)), np.array([Q_a] + list(y)) positive = True if np.sign(min(y)) in (0, 1) else False width = 0.5 bars = pylab.bar(x, y, color=colours, width=width) y_ticks_steps = 10 pylab.yticks(range(0 if positive else -100, 100 + y_ticks_steps, y_ticks_steps)) pylab.xticks(x + width / 2, ['Qa'] + ['Q{0}'.format(index) for index in x[1:]]) def label_bars(bars): """ Add labels above given bars. """ for bar in bars: y = bar.get_y() height = bar.get_height() value = height if np.sign(y) in (0, 1) else -height axis.text(bar.get_x() + bar.get_width() / 2, 0.025 * height + height + y, '{0:.1f}'.format(value), ha='center', va='bottom') label_bars(bars) settings.update({ 'title': 'Colour Quality', 'grid': True, 'grid_axis': 'y', 'x_tighten': True, 'y_tighten': True, 'limits': [-width, len(Q_as) + width * 2, 0 if positive else -110, 110], 'aspect': 1 / ((110 if positive else 220) / (width + len(Q_as) + width * 2))}) settings.update(kwargs) boundaries(**settings) decorate(**settings) return display(**settings)