%Chapter 7, Fig 7.11 %Eric Dubois, updated 2018-12-13 %Plot the CIE 1931 XYZ chromaticity diagram % data files obtained from CVRL website %Data files should be placed in a data directory on the MATLAB path. clear all, close all; %read the CIE 1931 XYZ color matching functions. %they are defined from 360 nm to 830 nm in steps of 1 nm. xyz = dlmread('ciexyz31_1.txt',','); %plot chromaticity diagram % %compute chromaticities of the monochromatic lights npts=size(xyz); S = xyz(:,2:4) * [1 1 1]'; xyzc = [xyz(:,2)./S xyz(:,3)./S xyz(:,4)./S]; figure; plot(xyzc(:,1),xyzc(:,2),'k'); xlabel('\it c_X'),ylabel('\it c_Y'); axis square; axis([0 .9 0 .9]); %line of purples xl = linspace(xyzc(1,1), xyzc(npts(1),1)); yl = linspace(xyzc(1,2), xyzc(npts(1),2)); hold; plot(xl,yl,'k'); %show specific wavelengths on the plot lamshow =[400 470 (480:5:505) (510:10:590) 610 700]; lamindex = lamshow - 359; plot(xyzc(lamindex,1),xyzc(lamindex,2),'kx') for ind =2:9 text(xyzc(lamindex(ind),1)+ 0.023, xyzc(lamindex(ind),2)+0.015, num2str(lamindex(ind)+359), 'BackgroundColor',[1 1 1], 'Margin',1); end for ind =11:19 text(xyzc(lamindex(ind),1)+ 0.025, xyzc(lamindex(ind),2)+0.022, num2str(lamindex(ind)+359), 'BackgroundColor',[1 1 1], 'Margin',1); end text(xyzc(lamindex(1),1)+ 0.02, xyzc(lamindex(1),2)+0.028, num2str(lamindex(1)+359), 'BackgroundColor',[1 1 1], 'Margin',1); text(xyzc(lamindex(10),1)+ 0.012, xyzc(lamindex(10),2)+0.034, num2str(lamindex(10)+359), 'BackgroundColor',[1 1 1], 'Margin',1); set(gca,'fontname','times') %set the plot font to Times set(gcf,'Color',[1 1 1]);