Skip to content

Instantly share code, notes, and snippets.

@KelSolaar
Last active August 13, 2016 20:57
Show Gist options
  • Save KelSolaar/a8bc7434166a1caa56a02ff74d0a1f6f to your computer and use it in GitHub Desktop.
Save KelSolaar/a8bc7434166a1caa56a02ff74d0a1f6f to your computer and use it in GitHub Desktop.
Vishal - Plotting Spds
import numpy as np
import pylab
import colour
from colour.plotting import *
fields = ('wl', 'a', 'b', 'c', 'd', 'e')
spds = colour.read_spds_from_csv_file(
'/Users/kelsolaar/Documents/Development/colour-science/colour-ramblings/ramblings_modules/vishal/data_set.txt',
delimiter=' ',
fields=fields)
def spds_CIE_1931_chromaticity_diagram_plot(
spds,
cmfs='CIE 1931 2 Degree Standard Observer',
annotate=True,
**kwargs):
"""
Plots given spectral power distribution chromaticity coordinates into the
*CIE 1931 Chromaticity Diagram*.
Parameters
----------
spds : array_like, optional
Spectral power distributions to plot.
cmfs : unicode, optional
Standard observer colour matching functions used for diagram bounds.
annotate : bool
Should resulting chromaticity coordinates annotated with their
respective spectral power distribution names.
\**kwargs : dict, optional
Keywords arguments.
Returns
-------
Figure
Current figure or None.
Examples
--------
>>> from colour import ILLUMINANTS_RELATIVE_SPDS
>>> A = ILLUMINANTS_RELATIVE_SPDS['A']
>>> D65 = ILLUMINANTS_RELATIVE_SPDS['D65']
>>> spds_CIE_1931_chromaticity_diagram_plot([A, D65]) # doctest: +SKIP
"""
settings = {}
settings.update(kwargs)
settings.update({'standalone': False})
CIE_1931_chromaticity_diagram_plot(cmfs=cmfs, **settings)
xy = []
for spd in spds:
XYZ = colour.spectral_to_XYZ(spd) / 100
xy.append(colour.XYZ_to_xy(XYZ))
xy = np.array(xy)
pylab.plot(xy[..., 0], xy[..., 1], 'o--', color='black')
settings.update({
'x_tighten': True,
'y_tighten': True,
'limits': (-0.1, 0.9, -0.1, 0.9),
'standalone': True})
settings.update(kwargs)
boundaries(**settings)
decorate(**settings)
return display(**settings)
spds_CIE_1931_chromaticity_diagram_plot(spds.values())
spd_names = spds.keys()
spds = spds.values()
XYZ = [colour.spectral_to_XYZ(spd) / 100 for spd in spds]
RGB = colour.XYZ_to_sRGB(XYZ)
colour_parameters = [ColourParameter(spd_names[i], np.clip(RGB[i] , 0, 1))
for i in range(len(spd_names))]
multi_colour_plot(colour_parameters, across=len(spd_names), spacing=0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment