用 CIE 色度衰减填充光谱曲线的区域以在 pgfplots 中生成 CIE 色度图

用 CIE 色度衰减填充光谱曲线的区域以在 pgfplots 中生成 CIE 色度图

我正在尝试使用 pgfplots 绘制 CIE 色度图。我发现TikZ 色度图它展示了使用 tikz 的非常漂亮的解决方案。为了方便地在 CIE 色度图上绘制数据集,我想将此示例转移到 pgfplots 和可变绘图大小,但我不知道如何完成。

问题是:如何使用符合 CIE 的颜色褪色来填充 pgfplot 中光谱曲线内的区域,就像在参考问题中显示的那样,以便我可以轻松地在其上放置带有 pgfplots 的附加图,以及如何使褪色动态化,使其能够自行缩放到绘制的光谱曲线?

我不太熟悉 pgfplots 和填充背景所以我的尝试可能无法实现。

这是一个 MWE,它基本上是一张 pgfplots 图片,其中集成了来自引用问题的组件:

\documentclass{standalone}
\usepackage{luatex85}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{fadings}

\def\colorspaceline{(0.1738,0.0049)(0.1736,0.0049)(0.1733,0.0048)(0.1730,0.0048)(0.1726,0.0048)(0.1721,0.0048)(0.1714,0.0051)(0.1703,0.0058)(0.1689,0.0069)(0.1669,0.0086)(0.1644,0.0109)(0.1611,0.0138)(0.1566,0.0177)(0.1510,0.0227)(0.1440,0.0297)(0.1355,0.0399)(0.1241,0.0578)(0.1096,0.0868)(0.0913,0.1327)(0.0687,0.2007)(0.0454,0.2950)(0.0235,0.4127)(0.0082,0.5384)(0.0039,0.6548)(0.0139,0.7502)(0.0389,0.8120)(0.0743,0.8338)(0.1142,0.8262)(0.1547,0.8059)(0.1929,0.7816)(0.2296,0.7543)(0.2658,0.7243)(0.3016,0.6923)(0.3373,0.6589)(0.3731,0.6245)(0.4087,0.5896)(0.4441,0.5547)(0.4788,0.5202)(0.5125,0.4866)(0.5448,0.4544)(0.5752,0.4242)(0.6029,0.3965)(0.6270,0.3725)(0.6482,0.3514)(0.6658,0.3340)(0.6801,0.3197)(0.6915,0.3083)(0.7006,0.2993)(0.7079,0.2920)(0.7140,0.2859)(0.7190,0.2809)(0.7230,0.2770)(0.7260,0.2740)(0.7283,0.2717)(0.7300,0.2700)(0.7311,0.2689)(0.7320,0.2680)(0.7327,0.2673)(0.7334,0.2666)(0.7340,0.2660)(0.7344,0.2656)(0.7346,0.2654)(0.7347,0.2653)}


% Derived transformation matrix
\def\XYZtoRGB{
  { 3.2410}{-1.5374}{-0.4986}
  {-0.9692}{ 1.8760}{ 0.0416}
  { 0.0556}{-0.2040}{ 1.0570}}

 % Linear color to gamma corrected transform
\def\gammaCorrect{
  dup 0.0031308 le                    % if < 0.0031308
  {12.92 mul}                         % then linear transform
  {1 2.4 div exp 1.055 mul -0.055 add}% else power transform
  ifelse }

% ------------------------------------------------------------- TYPE 4 HELPERS

\def\scalarProduct#1#2#3{
  #3 mul     exch
  #2 mul add exch
  #1 mul add }

\def\applyMatrix#1#2#3#4#5#6#7#8#9{
  3 copy 3 copy
  \scalarProduct{#7}{#8}{#9} 7 1 roll
  \scalarProduct{#4}{#5}{#6} 5 1 roll
  \scalarProduct{#1}{#2}{#3} 3 1 roll }

\def\xyYtoXYZ{                        % x y Y
  3 copy 3 1 roll                     % x y Y Y x y
  add neg 1 add mul 2 index div       % x y Y Y*(-(x+y)+1)/y=Z
  4 1 roll                            % Z x y Y
  dup                                 % Z x y Y Y=Y
  5 1 roll                            % Y Z x y Y
  3 2 roll                            % Y Z y Y x
  mul exch div                        % Y Z Y*x/y=X
  3 1 roll }                          % X Y Z

\def\gammaCorrectVector{
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll}


\begin{document}
\begin{tikzpicture}

\pgfdeclarefunctionalshading{colorspace}
  {\pgfpointorigin}{\pgfpoint{1000bp}{1000bp}}{}{
    1000 div exch 1000 div exch       % x y   (chromaticity)
    1.0                               % x y Y (chromaticity+luminance)
    \xyYtoXYZ                         % X Y Z (XYZ)
    \expandafter\applyMatrix\XYZtoRGB % R G B (sRGB linear)
    \gammaCorrectVector }             % R G B (sRGB gamma corrected)

        \begin{axis}[
        ymin=0,
        ymax=0.85,
        xmin=0,
        xmax=0.75,
        xlabel=x,
        ylabel=y,
        width=5cm,
        height=5cm,
        clip=false]
        %Spektrale Rand des CIE Raums
        \addplot[no marks,black,smooth] coordinates {\colorspaceline} -- cycle;

        \clip [smooth] plot coordinates {\colorspaceline} -- cycle;
        % sRGB color space
        \pgfuseshading{colorspace}

        \end{axis}
\end{tikzpicture}

\end{document}

据我所知,阴影是静态的,不能自动适应图中绘制的光谱曲线。将 MWE 视为寻找解决方案的不良起点。

编辑: 我使用了 BambOo 提供的在 tikz 图片周围叠加轴的代码。单独使用时它可以工作,但在我的例子中,将其集成到更大的文档中会破坏 CIE 颜色阴影,并且该区域将显示为灰色 + PDF 查看器会识别出该页面上的错误。正如 PGF/tikz 文档中所述,使用函数进行褪色是脆弱的,这也可能发生在这里。

编辑: 从 pgfplots 添加绘图图形可能是一种实现此目的的方法。因此,需要一张清晰的色彩空间图片,该图片在色彩空间坐标系的定义位置上进行剪切。

答案1

运行xelatex

\documentclass{article}
\usepackage{pst-cie}
\begin{document}

\begin{pspicture}(-1,-1)(8.5,11)
\psChromaticityDiagram[Planck,trianglecolor=black]
\rput(5.5,8){\white \textbf{Colorspace sRGB}}
\end{pspicture} 

\end{document}

enter image description here

答案2

也许我误解了你的问题,但是你不能将 pgfplots 轴叠加到现有范围(取自你的链接帖子)吗?

编辑:我添加了一个缩放因子(手动),以便在将初始范围与轴环境叠加时获得所需的结果。

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning}

% ------------------------------------------------------------------- RAW DATA

% DATASET ORIGIN:
%  http://steve.hollasch.net/cgindex/color/freq-rgb.html
% Spectral stimuli colors - CIE 1931
\def\spectralLocus{ % xy coordinates from 390nm to 700nm in steps of 5nm
  (0.1738,0.0049)(0.1736,0.0049)(0.1733,0.0048)(0.1730,0.0048)(0.1726,0.0048)
  (0.1721,0.0048)(0.1714,0.0051)(0.1703,0.0058)(0.1689,0.0069)(0.1669,0.0086)
  (0.1644,0.0109)(0.1611,0.0138)(0.1566,0.0177)(0.1510,0.0227)(0.1440,0.0297)
  (0.1355,0.0399)(0.1241,0.0578)(0.1096,0.0868)(0.0913,0.1327)(0.0687,0.2007)
  (0.0454,0.2950)(0.0235,0.4127)(0.0082,0.5384)(0.0039,0.6548)(0.0139,0.7502)
  (0.0389,0.8120)(0.0743,0.8338)(0.1142,0.8262)(0.1547,0.8059)(0.1929,0.7816)
  (0.2296,0.7543)(0.2658,0.7243)(0.3016,0.6923)(0.3373,0.6589)(0.3731,0.6245)
  (0.4087,0.5896)(0.4441,0.5547)(0.4788,0.5202)(0.5125,0.4866)(0.5448,0.4544)
  (0.5752,0.4242)(0.6029,0.3965)(0.6270,0.3725)(0.6482,0.3514)(0.6658,0.3340)
  (0.6801,0.3197)(0.6915,0.3083)(0.7006,0.2993)(0.7079,0.2920)(0.7140,0.2859)
  (0.7190,0.2809)(0.7230,0.2770)(0.7260,0.2740)(0.7283,0.2717)(0.7300,0.2700)
  (0.7311,0.2689)(0.7320,0.2680)(0.7327,0.2673)(0.7334,0.2666)(0.7340,0.2660)
  (0.7344,0.2656)(0.7346,0.2654)(0.7347,0.2653)}

% DATASET ORIGIN:
%  http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
% Blackbody colors - CIE 1931
\def\planckianLocus{ % xy coordinates from 1000K to 40000K in steps of 100K
  (0.6499,0.3474)(0.6361,0.3594)(0.6226,0.3703)(0.6095,0.3801)(0.5966,0.3887)
  (0.5841,0.3962)(0.5720,0.4025)(0.5601,0.4076)(0.5486,0.4118)(0.5375,0.4150)
  (0.5267,0.4173)(0.5162,0.4188)(0.5062,0.4196)(0.4965,0.4198)(0.4872,0.4194)
  (0.4782,0.4186)(0.4696,0.4173)(0.4614,0.4158)(0.4535,0.4139)(0.4460,0.4118)
  (0.4388,0.4095)(0.4320,0.4070)(0.4254,0.4044)(0.4192,0.4018)(0.4132,0.3990)
  (0.4075,0.3962)(0.4021,0.3934)(0.3969,0.3905)(0.3919,0.3877)(0.3872,0.3849)
  (0.3827,0.3820)(0.3784,0.3793)(0.3743,0.3765)(0.3704,0.3738)(0.3666,0.3711)
  (0.3631,0.3685)(0.3596,0.3659)(0.3563,0.3634)(0.3532,0.3609)(0.3502,0.3585)
  (0.3473,0.3561)(0.3446,0.3538)(0.3419,0.3516)(0.3394,0.3494)(0.3369,0.3472)
  (0.3346,0.3451)(0.3323,0.3431)(0.3302,0.3411)(0.3281,0.3392)(0.3261,0.3373)
  (0.3242,0.3355)(0.3223,0.3337)(0.3205,0.3319)(0.3188,0.3302)(0.3171,0.3286)
  (0.3155,0.3270)(0.3140,0.3254)(0.3125,0.3238)(0.3110,0.3224)(0.3097,0.3209)
  (0.3083,0.3195)(0.3070,0.3181)(0.3058,0.3168)(0.3045,0.3154)(0.3034,0.3142)
  (0.3022,0.3129)(0.3011,0.3117)(0.3000,0.3105)(0.2990,0.3094)(0.2980,0.3082)
  (0.2970,0.3071)(0.2961,0.3061)(0.2952,0.3050)(0.2943,0.3040)(0.2934,0.3030)
  (0.2926,0.3020)(0.2917,0.3011)(0.2910,0.3001)(0.2902,0.2992)(0.2894,0.2983)
  (0.2887,0.2975)(0.2880,0.2966)(0.2873,0.2958)(0.2866,0.2950)(0.2860,0.2942)
  (0.2853,0.2934)(0.2847,0.2927)(0.2841,0.2919)(0.2835,0.2912)(0.2829,0.2905)
  (0.2824,0.2898)(0.2818,0.2891)(0.2813,0.2884)(0.2807,0.2878)(0.2802,0.2871)
  (0.2797,0.2865)(0.2792,0.2859)(0.2788,0.2853)(0.2783,0.2847)(0.2778,0.2841)
  (0.2774,0.2836)(0.2770,0.2830)(0.2765,0.2825)(0.2761,0.2819)(0.2757,0.2814)
  (0.2753,0.2809)(0.2749,0.2804)(0.2745,0.2799)(0.2742,0.2794)(0.2738,0.2789)
  (0.2734,0.2785)(0.2731,0.2780)(0.2727,0.2776)(0.2724,0.2771)(0.2721,0.2767)
  (0.2717,0.2763)(0.2714,0.2758)(0.2711,0.2754)(0.2708,0.2750)(0.2705,0.2746)
  (0.2702,0.2742)(0.2699,0.2738)(0.2696,0.2735)(0.2694,0.2731)(0.2691,0.2727)
  (0.2688,0.2724)(0.2686,0.2720)(0.2683,0.2717)(0.2680,0.2713)(0.2678,0.2710)
  (0.2675,0.2707)(0.2673,0.2703)(0.2671,0.2700)(0.2668,0.2697)(0.2666,0.2694)
  (0.2664,0.2691)(0.2662,0.2688)(0.2659,0.2685)(0.2657,0.2682)(0.2655,0.2679)
  (0.2653,0.2676)(0.2651,0.2673)(0.2649,0.2671)(0.2647,0.2668)(0.2645,0.2665)
  (0.2643,0.2663)(0.2641,0.2660)(0.2639,0.2657)(0.2638,0.2655)(0.2636,0.2652)
  (0.2634,0.2650)(0.2632,0.2648)(0.2631,0.2645)(0.2629,0.2643)(0.2627,0.2641)
  (0.2626,0.2638)(0.2624,0.2636)(0.2622,0.2634)(0.2621,0.2632)(0.2619,0.2629)
  (0.2618,0.2627)(0.2616,0.2625)(0.2615,0.2623)(0.2613,0.2621)(0.2612,0.2619)
  (0.2610,0.2617)(0.2609,0.2615)(0.2608,0.2613)(0.2606,0.2611)(0.2605,0.2609)
  (0.2604,0.2607)(0.2602,0.2606)(0.2601,0.2604)(0.2600,0.2602)(0.2598,0.2600)
  (0.2597,0.2598)(0.2596,0.2597)(0.2595,0.2595)(0.2593,0.2593)(0.2592,0.2592)
  (0.2591,0.2590)(0.2590,0.2588)(0.2589,0.2587)(0.2588,0.2585)(0.2587,0.2584)
  (0.2586,0.2582)(0.2584,0.2580)(0.2583,0.2579)(0.2582,0.2577)(0.2581,0.2576)
  (0.2580,0.2574)(0.2579,0.2573)(0.2578,0.2572)(0.2577,0.2570)(0.2576,0.2569)
  (0.2575,0.2567)(0.2574,0.2566)(0.2573,0.2565)(0.2572,0.2563)(0.2571,0.2562)
  (0.2571,0.2561)(0.2570,0.2559)(0.2569,0.2558)(0.2568,0.2557)(0.2567,0.2555)
  (0.2566,0.2554)(0.2565,0.2553)(0.2564,0.2552)(0.2564,0.2550)(0.2563,0.2549)
  (0.2562,0.2548)(0.2561,0.2547)(0.2560,0.2546)(0.2559,0.2545)(0.2559,0.2543)
  (0.2558,0.2542)(0.2557,0.2541)(0.2556,0.2540)(0.2556,0.2539)(0.2555,0.2538)
  (0.2554,0.2537)(0.2553,0.2536)(0.2553,0.2535)(0.2552,0.2534)(0.2551,0.2533)
  (0.2551,0.2532)(0.2550,0.2531)(0.2549,0.2530)(0.2548,0.2529)(0.2548,0.2528)
  (0.2547,0.2527)(0.2546,0.2526)(0.2546,0.2525)(0.2545,0.2524)(0.2544,0.2523)
  (0.2544,0.2522)(0.2543,0.2521)(0.2543,0.2520)(0.2542,0.2519)(0.2541,0.2518)
  (0.2541,0.2517)(0.2540,0.2516)(0.2540,0.2516)(0.2539,0.2515)(0.2538,0.2514)
  (0.2538,0.2513)(0.2537,0.2512)(0.2537,0.2511)(0.2536,0.2511)(0.2535,0.2510)
  (0.2535,0.2509)(0.2534,0.2508)(0.2534,0.2507)(0.2533,0.2507)(0.2533,0.2506)
  (0.2532,0.2505)(0.2532,0.2504)(0.2531,0.2503)(0.2531,0.2503)(0.2530,0.2502)
  (0.2530,0.2501)(0.2529,0.2500)(0.2529,0.2500)(0.2528,0.2499)(0.2528,0.2498)
  (0.2527,0.2497)(0.2527,0.2497)(0.2526,0.2496)(0.2526,0.2495)(0.2525,0.2495)
  (0.2525,0.2494)(0.2524,0.2493)(0.2524,0.2493)(0.2523,0.2492)(0.2523,0.2491)
  (0.2523,0.2491)(0.2522,0.2490)(0.2522,0.2489)(0.2521,0.2489)(0.2521,0.2488)
  (0.2520,0.2487)(0.2520,0.2487)(0.2519,0.2486)(0.2519,0.2485)(0.2519,0.2485)
  (0.2518,0.2484)(0.2518,0.2484)(0.2517,0.2483)(0.2517,0.2482)(0.2517,0.2482)
  (0.2516,0.2481)(0.2516,0.2481)(0.2515,0.2480)(0.2515,0.2480)(0.2515,0.2479)
  (0.2514,0.2478)(0.2514,0.2478)(0.2513,0.2477)(0.2513,0.2477)(0.2513,0.2476)
  (0.2512,0.2476)(0.2512,0.2475)(0.2512,0.2474)(0.2511,0.2474)(0.2511,0.2473)
  (0.2511,0.2473)(0.2510,0.2472)(0.2510,0.2472)(0.2509,0.2471)(0.2509,0.2471)
  (0.2509,0.2470)(0.2508,0.2470)(0.2508,0.2469)(0.2508,0.2469)(0.2507,0.2468)
  (0.2507,0.2468)(0.2507,0.2467)(0.2506,0.2467)(0.2506,0.2466)(0.2506,0.2466)
  (0.2505,0.2465)(0.2505,0.2465)(0.2505,0.2464)(0.2505,0.2464)(0.2504,0.2463)
  (0.2504,0.2463)(0.2504,0.2463)(0.2503,0.2462)(0.2503,0.2462)(0.2503,0.2461)
  (0.2502,0.2461)(0.2502,0.2460)(0.2502,0.2460)(0.2502,0.2459)(0.2501,0.2459)
  (0.2501,0.2459)(0.2501,0.2458)(0.2500,0.2458)(0.2500,0.2457)(0.2500,0.2457)
  (0.2500,0.2456)(0.2499,0.2456)(0.2499,0.2456)(0.2499,0.2455)(0.2498,0.2455)
  (0.2498,0.2454)(0.2498,0.2454)(0.2498,0.2454)(0.2497,0.2453)(0.2497,0.2453)
  (0.2497,0.2452)(0.2497,0.2452)(0.2496,0.2452)(0.2496,0.2451)(0.2496,0.2451)
  (0.2496,0.2450)(0.2495,0.2450)(0.2495,0.2450)(0.2495,0.2449)(0.2495,0.2449)
  (0.2494,0.2449)(0.2494,0.2448)(0.2494,0.2448)(0.2494,0.2447)(0.2493,0.2447)
  (0.2493,0.2447)(0.2493,0.2446)(0.2493,0.2446)(0.2492,0.2446)(0.2492,0.2445)
  (0.2492,0.2445)(0.2492,0.2445)(0.2491,0.2444)(0.2491,0.2444)(0.2491,0.2444)
  (0.2491,0.2443)(0.2491,0.2443)(0.2490,0.2443)(0.2490,0.2442)(0.2490,0.2442)
  (0.2490,0.2442)(0.2489,0.2441)(0.2489,0.2441)(0.2489,0.2441)(0.2489,0.2440)
  (0.2489,0.2440)(0.2488,0.2440)(0.2488,0.2439)(0.2488,0.2439)(0.2488,0.2439)
  (0.2487,0.2438)}

% ---------------------------------------------- sRGB COLORSPACE SPECIFICATION

% DATASET ORIGIN: http://www.color.org/sRGB.xalter

% CIE chromaticities for ITU-R BT.709 reference primaries
\def\primariesLoci{
  (0.6400,0.3300)  % R
  (0.3000,0.6000)  % G
  (0.1500,0.0600)} % B

% CIE standard illuminant D65
\def\whitepointLocus{
  (0.3127,0.3290)}

% Derived transformation matrix
\def\XYZtoRGB{
  { 3.2410}{-1.5374}{-0.4986}
  {-0.9692}{ 1.8760}{ 0.0416}
  { 0.0556}{-0.2040}{ 1.0570}}

 % Linear color to gamma corrected transform
\def\gammaCorrect{
  dup 0.0031308 le                    % if < 0.0031308
  {12.92 mul}                         % then linear transform
  {1 2.4 div exp 1.055 mul -0.055 add}% else power transform
  ifelse }

% ------------------------------------------------------------- TYPE 4 HELPERS

\def\scalarProduct#1#2#3{
  #3 mul     exch
  #2 mul add exch
  #1 mul add }

\def\applyMatrix#1#2#3#4#5#6#7#8#9{
  3 copy 3 copy
  \scalarProduct{#7}{#8}{#9} 7 1 roll
  \scalarProduct{#4}{#5}{#6} 5 1 roll
  \scalarProduct{#1}{#2}{#3} 3 1 roll }

\def\xyYtoXYZ{                        % x y Y
  3 copy 3 1 roll                     % x y Y Y x y
  add neg 1 add mul 2 index div       % x y Y Y*(-(x+y)+1)/y=Z
  4 1 roll                            % Z x y Y
  dup                                 % Z x y Y Y=Y
  5 1 roll                            % Y Z x y Y
  3 2 roll                            % Y Z y Y x
  mul exch div                        % Y Z Y*x/y=X
  3 1 roll }                          % X Y Z

\def\gammaCorrectVector{
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll}

% -------------------------------------------------------------------- DRAWING

\begin{document}
\begin{tikzpicture}

\pgfdeclarefunctionalshading{colorspace}
  {\pgfpointorigin}{\pgfpoint{100bp}{100bp}}{}{
    100 div exch 100 div exch       % x y   (chromaticity)
    1.0                               % x y Y (chromaticity+luminance)
    \xyYtoXYZ                         % X Y Z (XYZ)
    \expandafter\applyMatrix\XYZtoRGB % R G B (sRGB linear)
    \gammaCorrectVector }             % R G B (sRGB gamma corrected)

\begin{scope} [shift={(-50bp,-50bp)}, scale=10bp/1cm]
  % Background + viewport
  %\fill [red] (0,0) rectangle (10,10);
  %\useasboundingbox (0,0) rectangle (10,10);
  % xy grid
  %\draw [dashed, gray] grid (10,10);
  \begin{scope} [scale=10]
    % Spectral locus marks
    \path [mark=*, mark repeat=2, white]
      plot [mark size=0.10, mark phase=1] coordinates {\spectralLocus}
      plot [mark size=0.05, mark phase=2] coordinates {\spectralLocus};
    % Smooth spectral locus contour for clipping
    \clip [smooth] plot coordinates {\spectralLocus} -- cycle;
    % sRGB color space
    \pgfuseshading{colorspace}
    % Standard illuminant mark
    \draw [gray] \whitepointLocus circle (0.005);
    % Reference primaries gamut
    \fill [black, even odd rule, opacity=0.5]
      rectangle +(1,1) plot coordinates {\primariesLoci} -- cycle;
    % Planckian locus markings
    \path [mark=*,gray]
      plot [mark size=0.05, mark repeat=10] coordinates {\planckianLocus}
      plot [mark size=0.01, mark repeat=1 ] coordinates {\planckianLocus};
  \end{scope}
\end{scope}

\begin{axis} [
  xmajorgrids,ymajorgrids,major grid style={dashed},
  at={(current bounding box.south west)},
  scale=9.27bp/1cm,
  xmin=0,xmax=1,ymin=0,ymax=1,
  width=350bp,height=350bp,
  axis on top=false,
  xtick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1},
  ytick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1}]
  \addplot [red,thick,domain=0:1,samples=100] {x};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

编辑

pgfplots集成角度来说,这个更接近,但是,我不知道如何正确设置着色器,所有缩放因子混在一起让我的思绪混乱。我会尝试稍后完成我的回答。

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning}

% ------------------------------------------------------------------- RAW DATA

% DATASET ORIGIN:
%  http://steve.hollasch.net/cgindex/color/freq-rgb.html
% Spectral stimuli colors - CIE 1931
\def\spectralLocus{ % xy coordinates from 390nm to 700nm in steps of 5nm
  (0.1738,0.0049)(0.1736,0.0049)(0.1733,0.0048)(0.1730,0.0048)(0.1726,0.0048)
  (0.1721,0.0048)(0.1714,0.0051)(0.1703,0.0058)(0.1689,0.0069)(0.1669,0.0086)
  (0.1644,0.0109)(0.1611,0.0138)(0.1566,0.0177)(0.1510,0.0227)(0.1440,0.0297)
  (0.1355,0.0399)(0.1241,0.0578)(0.1096,0.0868)(0.0913,0.1327)(0.0687,0.2007)
  (0.0454,0.2950)(0.0235,0.4127)(0.0082,0.5384)(0.0039,0.6548)(0.0139,0.7502)
  (0.0389,0.8120)(0.0743,0.8338)(0.1142,0.8262)(0.1547,0.8059)(0.1929,0.7816)
  (0.2296,0.7543)(0.2658,0.7243)(0.3016,0.6923)(0.3373,0.6589)(0.3731,0.6245)
  (0.4087,0.5896)(0.4441,0.5547)(0.4788,0.5202)(0.5125,0.4866)(0.5448,0.4544)
  (0.5752,0.4242)(0.6029,0.3965)(0.6270,0.3725)(0.6482,0.3514)(0.6658,0.3340)
  (0.6801,0.3197)(0.6915,0.3083)(0.7006,0.2993)(0.7079,0.2920)(0.7140,0.2859)
  (0.7190,0.2809)(0.7230,0.2770)(0.7260,0.2740)(0.7283,0.2717)(0.7300,0.2700)
  (0.7311,0.2689)(0.7320,0.2680)(0.7327,0.2673)(0.7334,0.2666)(0.7340,0.2660)
  (0.7344,0.2656)(0.7346,0.2654)(0.7347,0.2653)}

% DATASET ORIGIN:
%  http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
% Blackbody colors - CIE 1931
\def\planckianLocus{ % xy coordinates from 1000K to 40000K in steps of 100K
  (0.6499,0.3474)(0.6361,0.3594)(0.6226,0.3703)(0.6095,0.3801)(0.5966,0.3887)
  (0.5841,0.3962)(0.5720,0.4025)(0.5601,0.4076)(0.5486,0.4118)(0.5375,0.4150)
  (0.5267,0.4173)(0.5162,0.4188)(0.5062,0.4196)(0.4965,0.4198)(0.4872,0.4194)
  (0.4782,0.4186)(0.4696,0.4173)(0.4614,0.4158)(0.4535,0.4139)(0.4460,0.4118)
  (0.4388,0.4095)(0.4320,0.4070)(0.4254,0.4044)(0.4192,0.4018)(0.4132,0.3990)
  (0.4075,0.3962)(0.4021,0.3934)(0.3969,0.3905)(0.3919,0.3877)(0.3872,0.3849)
  (0.3827,0.3820)(0.3784,0.3793)(0.3743,0.3765)(0.3704,0.3738)(0.3666,0.3711)
  (0.3631,0.3685)(0.3596,0.3659)(0.3563,0.3634)(0.3532,0.3609)(0.3502,0.3585)
  (0.3473,0.3561)(0.3446,0.3538)(0.3419,0.3516)(0.3394,0.3494)(0.3369,0.3472)
  (0.3346,0.3451)(0.3323,0.3431)(0.3302,0.3411)(0.3281,0.3392)(0.3261,0.3373)
  (0.3242,0.3355)(0.3223,0.3337)(0.3205,0.3319)(0.3188,0.3302)(0.3171,0.3286)
  (0.3155,0.3270)(0.3140,0.3254)(0.3125,0.3238)(0.3110,0.3224)(0.3097,0.3209)
  (0.3083,0.3195)(0.3070,0.3181)(0.3058,0.3168)(0.3045,0.3154)(0.3034,0.3142)
  (0.3022,0.3129)(0.3011,0.3117)(0.3000,0.3105)(0.2990,0.3094)(0.2980,0.3082)
  (0.2970,0.3071)(0.2961,0.3061)(0.2952,0.3050)(0.2943,0.3040)(0.2934,0.3030)
  (0.2926,0.3020)(0.2917,0.3011)(0.2910,0.3001)(0.2902,0.2992)(0.2894,0.2983)
  (0.2887,0.2975)(0.2880,0.2966)(0.2873,0.2958)(0.2866,0.2950)(0.2860,0.2942)
  (0.2853,0.2934)(0.2847,0.2927)(0.2841,0.2919)(0.2835,0.2912)(0.2829,0.2905)
  (0.2824,0.2898)(0.2818,0.2891)(0.2813,0.2884)(0.2807,0.2878)(0.2802,0.2871)
  (0.2797,0.2865)(0.2792,0.2859)(0.2788,0.2853)(0.2783,0.2847)(0.2778,0.2841)
  (0.2774,0.2836)(0.2770,0.2830)(0.2765,0.2825)(0.2761,0.2819)(0.2757,0.2814)
  (0.2753,0.2809)(0.2749,0.2804)(0.2745,0.2799)(0.2742,0.2794)(0.2738,0.2789)
  (0.2734,0.2785)(0.2731,0.2780)(0.2727,0.2776)(0.2724,0.2771)(0.2721,0.2767)
  (0.2717,0.2763)(0.2714,0.2758)(0.2711,0.2754)(0.2708,0.2750)(0.2705,0.2746)
  (0.2702,0.2742)(0.2699,0.2738)(0.2696,0.2735)(0.2694,0.2731)(0.2691,0.2727)
  (0.2688,0.2724)(0.2686,0.2720)(0.2683,0.2717)(0.2680,0.2713)(0.2678,0.2710)
  (0.2675,0.2707)(0.2673,0.2703)(0.2671,0.2700)(0.2668,0.2697)(0.2666,0.2694)
  (0.2664,0.2691)(0.2662,0.2688)(0.2659,0.2685)(0.2657,0.2682)(0.2655,0.2679)
  (0.2653,0.2676)(0.2651,0.2673)(0.2649,0.2671)(0.2647,0.2668)(0.2645,0.2665)
  (0.2643,0.2663)(0.2641,0.2660)(0.2639,0.2657)(0.2638,0.2655)(0.2636,0.2652)
  (0.2634,0.2650)(0.2632,0.2648)(0.2631,0.2645)(0.2629,0.2643)(0.2627,0.2641)
  (0.2626,0.2638)(0.2624,0.2636)(0.2622,0.2634)(0.2621,0.2632)(0.2619,0.2629)
  (0.2618,0.2627)(0.2616,0.2625)(0.2615,0.2623)(0.2613,0.2621)(0.2612,0.2619)
  (0.2610,0.2617)(0.2609,0.2615)(0.2608,0.2613)(0.2606,0.2611)(0.2605,0.2609)
  (0.2604,0.2607)(0.2602,0.2606)(0.2601,0.2604)(0.2600,0.2602)(0.2598,0.2600)
  (0.2597,0.2598)(0.2596,0.2597)(0.2595,0.2595)(0.2593,0.2593)(0.2592,0.2592)
  (0.2591,0.2590)(0.2590,0.2588)(0.2589,0.2587)(0.2588,0.2585)(0.2587,0.2584)
  (0.2586,0.2582)(0.2584,0.2580)(0.2583,0.2579)(0.2582,0.2577)(0.2581,0.2576)
  (0.2580,0.2574)(0.2579,0.2573)(0.2578,0.2572)(0.2577,0.2570)(0.2576,0.2569)
  (0.2575,0.2567)(0.2574,0.2566)(0.2573,0.2565)(0.2572,0.2563)(0.2571,0.2562)
  (0.2571,0.2561)(0.2570,0.2559)(0.2569,0.2558)(0.2568,0.2557)(0.2567,0.2555)
  (0.2566,0.2554)(0.2565,0.2553)(0.2564,0.2552)(0.2564,0.2550)(0.2563,0.2549)
  (0.2562,0.2548)(0.2561,0.2547)(0.2560,0.2546)(0.2559,0.2545)(0.2559,0.2543)
  (0.2558,0.2542)(0.2557,0.2541)(0.2556,0.2540)(0.2556,0.2539)(0.2555,0.2538)
  (0.2554,0.2537)(0.2553,0.2536)(0.2553,0.2535)(0.2552,0.2534)(0.2551,0.2533)
  (0.2551,0.2532)(0.2550,0.2531)(0.2549,0.2530)(0.2548,0.2529)(0.2548,0.2528)
  (0.2547,0.2527)(0.2546,0.2526)(0.2546,0.2525)(0.2545,0.2524)(0.2544,0.2523)
  (0.2544,0.2522)(0.2543,0.2521)(0.2543,0.2520)(0.2542,0.2519)(0.2541,0.2518)
  (0.2541,0.2517)(0.2540,0.2516)(0.2540,0.2516)(0.2539,0.2515)(0.2538,0.2514)
  (0.2538,0.2513)(0.2537,0.2512)(0.2537,0.2511)(0.2536,0.2511)(0.2535,0.2510)
  (0.2535,0.2509)(0.2534,0.2508)(0.2534,0.2507)(0.2533,0.2507)(0.2533,0.2506)
  (0.2532,0.2505)(0.2532,0.2504)(0.2531,0.2503)(0.2531,0.2503)(0.2530,0.2502)
  (0.2530,0.2501)(0.2529,0.2500)(0.2529,0.2500)(0.2528,0.2499)(0.2528,0.2498)
  (0.2527,0.2497)(0.2527,0.2497)(0.2526,0.2496)(0.2526,0.2495)(0.2525,0.2495)
  (0.2525,0.2494)(0.2524,0.2493)(0.2524,0.2493)(0.2523,0.2492)(0.2523,0.2491)
  (0.2523,0.2491)(0.2522,0.2490)(0.2522,0.2489)(0.2521,0.2489)(0.2521,0.2488)
  (0.2520,0.2487)(0.2520,0.2487)(0.2519,0.2486)(0.2519,0.2485)(0.2519,0.2485)
  (0.2518,0.2484)(0.2518,0.2484)(0.2517,0.2483)(0.2517,0.2482)(0.2517,0.2482)
  (0.2516,0.2481)(0.2516,0.2481)(0.2515,0.2480)(0.2515,0.2480)(0.2515,0.2479)
  (0.2514,0.2478)(0.2514,0.2478)(0.2513,0.2477)(0.2513,0.2477)(0.2513,0.2476)
  (0.2512,0.2476)(0.2512,0.2475)(0.2512,0.2474)(0.2511,0.2474)(0.2511,0.2473)
  (0.2511,0.2473)(0.2510,0.2472)(0.2510,0.2472)(0.2509,0.2471)(0.2509,0.2471)
  (0.2509,0.2470)(0.2508,0.2470)(0.2508,0.2469)(0.2508,0.2469)(0.2507,0.2468)
  (0.2507,0.2468)(0.2507,0.2467)(0.2506,0.2467)(0.2506,0.2466)(0.2506,0.2466)
  (0.2505,0.2465)(0.2505,0.2465)(0.2505,0.2464)(0.2505,0.2464)(0.2504,0.2463)
  (0.2504,0.2463)(0.2504,0.2463)(0.2503,0.2462)(0.2503,0.2462)(0.2503,0.2461)
  (0.2502,0.2461)(0.2502,0.2460)(0.2502,0.2460)(0.2502,0.2459)(0.2501,0.2459)
  (0.2501,0.2459)(0.2501,0.2458)(0.2500,0.2458)(0.2500,0.2457)(0.2500,0.2457)
  (0.2500,0.2456)(0.2499,0.2456)(0.2499,0.2456)(0.2499,0.2455)(0.2498,0.2455)
  (0.2498,0.2454)(0.2498,0.2454)(0.2498,0.2454)(0.2497,0.2453)(0.2497,0.2453)
  (0.2497,0.2452)(0.2497,0.2452)(0.2496,0.2452)(0.2496,0.2451)(0.2496,0.2451)
  (0.2496,0.2450)(0.2495,0.2450)(0.2495,0.2450)(0.2495,0.2449)(0.2495,0.2449)
  (0.2494,0.2449)(0.2494,0.2448)(0.2494,0.2448)(0.2494,0.2447)(0.2493,0.2447)
  (0.2493,0.2447)(0.2493,0.2446)(0.2493,0.2446)(0.2492,0.2446)(0.2492,0.2445)
  (0.2492,0.2445)(0.2492,0.2445)(0.2491,0.2444)(0.2491,0.2444)(0.2491,0.2444)
  (0.2491,0.2443)(0.2491,0.2443)(0.2490,0.2443)(0.2490,0.2442)(0.2490,0.2442)
  (0.2490,0.2442)(0.2489,0.2441)(0.2489,0.2441)(0.2489,0.2441)(0.2489,0.2440)
  (0.2489,0.2440)(0.2488,0.2440)(0.2488,0.2439)(0.2488,0.2439)(0.2488,0.2439)
  (0.2487,0.2438)}

% ---------------------------------------------- sRGB COLORSPACE SPECIFICATION

% DATASET ORIGIN: http://www.color.org/sRGB.xalter

% CIE chromaticities for ITU-R BT.709 reference primaries
\def\primariesLoci{
  (0.6400,0.3300)  % R
  (0.3000,0.6000)  % G
  (0.1500,0.0600)} % B

% CIE standard illuminant D65
\def\whitepointLocus{
  (0.3127,0.3290)}

% Derived transformation matrix
\def\XYZtoRGB{
  { 3.2410}{-1.5374}{-0.4986}
  {-0.9692}{ 1.8760}{ 0.0416}
  { 0.0556}{-0.2040}{ 1.0570}}

 % Linear color to gamma corrected transform
\def\gammaCorrect{
  dup 0.0031308 le                    % if < 0.0031308
  {12.92 mul}                         % then linear transform
  {1 2.4 div exp 1.055 mul -0.055 add}% else power transform
  ifelse }

% ------------------------------------------------------------- TYPE 4 HELPERS

\def\scalarProduct#1#2#3{
  #3 mul     exch
  #2 mul add exch
  #1 mul add }

\def\applyMatrix#1#2#3#4#5#6#7#8#9{
  3 copy 3 copy
  \scalarProduct{#7}{#8}{#9} 7 1 roll
  \scalarProduct{#4}{#5}{#6} 5 1 roll
  \scalarProduct{#1}{#2}{#3} 3 1 roll }

\def\xyYtoXYZ{                        % x y Y
  3 copy 3 1 roll                     % x y Y Y x y
  add neg 1 add mul 2 index div       % x y Y Y*(-(x+y)+1)/y=Z
  4 1 roll                            % Z x y Y
  dup                                 % Z x y Y Y=Y
  5 1 roll                            % Y Z x y Y
  3 2 roll                            % Y Z y Y x
  mul exch div                        % Y Z Y*x/y=X
  3 1 roll }                          % X Y Z

\def\gammaCorrectVector{
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll
  \gammaCorrect 3 1 roll}

% -------------------------------------------------------------------- DRAWING

\begin{document}
\begin{tikzpicture}

\pgfdeclarefunctionalshading{colorspace}
  {\pgfpointorigin}{\pgfpoint{100bp}{100bp}}{}{
    1000 div exch 1000 div exch       % x y   (chromaticity)
    1.0                               % x y Y (chromaticity+luminance)
    \xyYtoXYZ                         % X Y Z (XYZ)
    \expandafter\applyMatrix\XYZtoRGB % R G B (sRGB linear)
    \gammaCorrectVector }             % R G B (sRGB gamma corrected)

\begin{axis} [axis background/.style={fill=black}, scale=200bp/5cm,xmajorgrids,ymajorgrids,major grid style={dashed},xmin=0,xmax=0.9,ymin=0,ymax=0.9,width=5cm,height=5cm]
    % Spectral locus marks
    \addplot [mark=*, mark repeat=2, white]
      plot [mark size=0.10, mark phase=1] coordinates {\spectralLocus}
      plot [mark size=0.05, mark phase=2] coordinates {\spectralLocus};

    \addplot [shading=colorspace] plot coordinates {\spectralLocus} -- cycle;
    % Standard illuminant mark
    \draw [gray] \whitepointLocus circle (0.005);
    % Reference primaries gamut
    \fill [black, even odd rule, opacity=0.5] rectangle +(1,1) plot coordinates {\primariesLoci} -- cycle;
    % Planckian locus markings
    \addplot [mark=*,gray]
      plot [mark size=0.05, mark repeat=10] coordinates {\planckianLocus}
      plot [mark size=0.01, mark repeat=1 ] coordinates {\planckianLocus};

  \addplot [red,thick,domain=0:0.8,samples=100] {x};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

相关内容