% Author: Izaak Neutelings (March 2019)
\documentclass[border=3pt,tikz]{standalone}
\tikzset{>=latex} % for LaTeX arrow head
\usepackage{pgfplots} % for the axis environment
\pgfplotsset{compat=1.13} % TikZ coordinates <-> axes coordinates
\usepackage{siunitx}

% redraw axis on top
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
\pgfplotsset{axis line on top/.style={after end axis/.append code={\pgfplotsdrawaxis}}
}

\definecolor{1000K}{rgb}{1,0.0337,0}
\definecolor{2000K}{rgb}{1,0.2647,0.0033}
\definecolor{3000K}{rgb}{1,0.4870,0.1411}
\definecolor{4000K}{rgb}{1,0.6636,0.3583}
\definecolor{5000K}{rgb}{1,0.7992,0.6045}
\definecolor{6000K}{rgb}{1,0.9019,0.8473}
\definecolor{8000K}{rgb}{0.7874,0.8187,1}
\definecolor{10000K}{rgb}{0.6268,0.7039,1}
\colorlet{myblue}{black!50!blue}
\colorlet{myred}{black!50!red}
\pgfdeclareverticalshading{rainbow}{100bp}{
  color(0bp)=(red); color(25bp)=(red); color(35bp)=(yellow);
  color(45bp)=(green); color(55bp)=(cyan); color(65bp)=(blue);
  color(75bp)=(violet); color(100bp)=(violet)
}

% PLANCK & RAYLEIGH-JEANS
% 2hc^2/lambda^5 = 2 * 6.62607015e-34 * 299792458^2
%                = 1.191042972e-16
%    W.m -> kW.nm: 1.191042972e26
%  hc/k lambda T = 6.62607015e-34*299792458/(1.38064852e-23)
%                = 0.01438777378
%         m -> nm: 0.01438777378e9
% 2ckT/lambda^4  = 2 * 299792458 * 1.38064852e-23
%                = 8.278160269e-15
%    W.m -> kW.nm: 8.278160269e18
\pgfmathdeclarefunction{planck}{2}{%
  \pgfmathparse{1.191042972e26/(#1^5)/(exp(0.01439e9/(#1*#2))-1)}%
}
\pgfmathdeclarefunction{rayleighjeans}{2}{%
  \pgfmathparse{8.278160269e18*#2/(#1^4)}%
}
\pgfmathdeclarefunction{wien}{2}{%
  \pgfmathparse{1.191042972e26/(#1^5)*exp(-0.01439e9/(#1*#2))}%
}

\begin{document}



% BLACK BODY - 5000K
\begin{tikzpicture}
  \def\N{50}
  \def\xmax{3000}
  \def\ymax{1.32e10}
  \def\tick#1#2{\draw[thick] (#1+.01*\ymax) -- (#1-.01*\ymax) node[below=-.5pt,scale=0.75] {#2};}
  \begin{axis}[every axis plot post/.append style={
               mark=none,domain=5:\xmax,samples=\N,smooth},
               xmin=(-.05*\xmax), xmax=(1.05*\xmax),
               ymin=(-.08*\ymax), ymax=(1.08*\ymax),
               restrict y to domain=0:\ymax,
               axis lines=middle,
               axis line style=thick,
               %enlargelimits=upper, % extend the axes a bit to the right and top
               tick style={black,thick},
               ticklabel style={scale=0.8},
               xtick style={draw=none}, xticklabels=none,
               xlabel={Wavelength $\lambda$ [nm]},
               ylabel={Power $P$ [kW/sr\,m$^2$\,nm]},
               xlabel style={at={(rel axis cs:0.5,0)},below=-2pt,font=\small},
               ylabel style={at={(rel axis cs:-0.1,0.5)},rotate=90},
               width=9cm, height=7cm,
               %clip=false
               tick scale binop=\times,
               every y tick scale label/.style={at={(rel axis cs:0,1)},anchor=south}]
              ]
    
    % RAINBOW
    \shade[shading=rainbow,shading angle=90,opacity=0.4] (380,0) rectangle (740,\ymax);
    \node[above=-1pt,scale=0.8] at (200,\ymax) {\strut UV}; % 10 - 400 nm
    \node[above=-1pt,scale=0.8] at (570,\ymax) {\strut optical}; % 380 - 740 nm
    \node[above=-1pt,scale=0.8] at (920,\ymax) {\strut IR}; % 740 - 1050 nm
    
    % PLANCK
    \addplot[very thick,red]    {planck(x,3000)};
    \addplot[very thick,orange] {planck(x,4000)};
    \addplot[very thick,blue]   {planck(x,5000)};
    %\addplot[dashed,thick,red,domain=1000:4000]    {rayleighjeans(x,3000)};
    %\addplot[dashed,thick,orange,domain=1000:4000] {rayleighjeans(x,4000)};
    \addplot[dashed,thick,blue,domain=1000:4000]   {rayleighjeans(x,5000)};
    %\addplot[dashed,thick,red,domain=1000:4000]    {wien(x,3000)};
    %\addplot[dashed,thick,orange,domain=1000:4000] {wien(x,4000)};
    %\addplot[dashed,thick,blue,domain=1000:4000]   {wien(x,5000)};
    
    % LABELS
    \node[above=0pt,scale=0.75,red] at (1000,{planck(1000,3000)}) {\SI{3000}{K}};
    \node[above right=-1pt,scale=0.75,orange] at (720,{planck(720,4000)}) {\SI{4000}{K}};
    \node[above right=-1pt,scale=0.75,blue] at (800,{planck(800,5000)}) {\SI{5000}{K}};
    \node[above right=-1pt,scale=0.75,blue] at (1500,{rayleighjeans(1500,5000)}) {\SI{5000}{K} Rayleigh-Jeans};
    
    % TICKS
    \tick{500,0}{500}
    \tick{1000,0}{1000}
    \tick{1500,0}{1500}
    \tick{2000,0}{2000}
    
  \end{axis}
\end{tikzpicture}



% BLACK BODY LOG-LOG
\begin{tikzpicture} %[scale=2]
  \def\N{40}
  \def\xmin{40}
  \def\xmax{4e5}
  \def\ymin{1e0}
  \def\ymax{3e12}
  \begin{loglogaxis}[every axis plot post/.append style={
               mark=none,domain=\xmin:\xmax,samples=\N,smooth},
               xmin=\xmin, xmax=(1.01*\xmax),
               ymin=\ymin, ymax=\ymax,
               restrict y to domain=0.1*\ymin:\ymax,
               log basis y=10,
               axis line style=thick,
               tick style={black,thick},
               ticklabel style={scale=0.8},
               xlabel={Wavelength $\lambda$ [nm]},
               ylabel={Power $P$ [kW/sr\,m$^2$\,nm]},
               xlabel style={at={(rel axis cs:0.5,0)},below=8pt},
               ylabel style={above=-2pt},
               legend style={at={(0.98,0.95)},anchor=north east,draw=none,fill=none,
                             nodes={scale=0.7, transform shape}},
               legend cell align={left},
               width=8cm, height=6cm,
               axis line on top
              ]
    
    % RAINBOW
    \shade[shading=rainbow,shading angle=90,opacity=0.4] (380,\ymin) rectangle (740,\ymax);
    
    % PLANCK
    \addplot[very thick,10000K] {planck(x,10000)};
    \addplot[very thick,6000K]  {planck(x,7500)};
    \addplot[very thick,5000K]  {planck(x,5000)};
    \addplot[very thick,3000K]  {planck(x,3000)};
    \addplot[very thick,2000K]  {planck(x,2000)};
    \addplot[very thick,1000K]  {planck(x,1000)};
    \addplot[very thick,black]  {planck(x, 500)};
    %\addplot[dashed,thick,black] {rayleighjeans(x,500)};
    
    % LEGENDS
    \addlegendentry{\SI{10000}{K}}
    \addlegendentry{\SI{7500}{K}}
    \addlegendentry{\SI{5000}{K}}
    \addlegendentry{\SI{3000}{K}}
    \addlegendentry{\SI{2000}{K}}
    \addlegendentry{\SI{1000}{K}}
    \addlegendentry{\SI{500}{K}}
    
  \end{loglogaxis}
\end{tikzpicture}



% BLACK BODY LOG-LOG - Rayleigh-Jeans / Wien, 300K
\begin{tikzpicture}
  \def\N{40}
  \def\xmin{1.5e3}
  \def\xmax{2e6}
  \def\ymin{5e-4}
  \def\ymax{3e4}
  \begin{loglogaxis}[every axis plot post/.append style={
               mark=none,domain=\xmin:\xmax,samples=\N,smooth},
               xmin=\xmin, xmax=(1.01*\xmax),
               ymin=\ymin, ymax=\ymax,
               restrict y to domain=0.1*\ymin:\ymax,
               log basis y=10,
               axis line style=thick,
               tick style={black,thick},
               ticklabel style={scale=0.8},
               %ticks=none,
               xlabel={Wavelength $\lambda$ [nm]},
               ylabel={Power $P$ [kW/sr\,m$^2$\,nm]},
               xlabel style={at={(rel axis cs:0.5,0)},below=8pt},
               ylabel style={above=-2pt},
               width=8cm, height=6cm,
               legend style={at={(0.14,0.15)},anchor=south west,draw=none,fill=none,font=\small},
               legend cell align={left},
               axis line on top
              ]
  	
    % PLANCK
    \addplot[very thick,black]  {planck(x,300)};
    \addplot[thick,blue] {rayleighjeans(x,300)};
    \addplot[thick,red]  {wien(x,300)};
    
    % LEGENDS
    \addlegendentry{Planck}
    \addlegendentry{Rayleigh-Jeans}
    \addlegendentry{Wien}
    \node[scale=1.] at (0.2*\xmax,0.01*\ymax) {$T=\SI{300}{K}$};
    
  \end{loglogaxis}
\end{tikzpicture}



% BLACK BODY LOG-LOG - Rayleigh-Jeans / Wien, 3000K
\begin{tikzpicture}
  \def\N{40}
  \def\xmin{1.5e2}
  \def\xmax{2e5}
  \def\ymin{5e1}
  \def\ymax{7e9}
  \begin{loglogaxis}[every axis plot post/.append style={
               mark=none,domain=\xmin:\xmax,samples=\N,smooth},
               xmin=\xmin, xmax=(1.01*\xmax),
               ymin=\ymin, ymax=\ymax,
               restrict y to domain=0.1*\ymin:\ymax,
               log basis y=10,
               axis line style=thick,
               tick style={black,thick},
               ticklabel style={scale=0.8},
               %ticks=none,
               xlabel={Wavelength $\lambda$ [nm]},
               ylabel={Power $P$ [kW/sr\,m$^2$\,nm]},
               xlabel style={at={(rel axis cs:0.5,0)},below=8pt},
               ylabel style={above=-2pt},
               width=8cm, height=6cm,
               legend style={at={(0.14,0.15)},anchor=south west,draw=none,fill=none,font=\small},
               legend cell align={left},
               axis line on top
              ]
  	
    % PLANCK
    \addplot[very thick,black]  {planck(x,3000)};
    \addplot[thick,blue] {rayleighjeans(x,3000)};
    \addplot[thick,red]  {wien(x,3000)};
    
    % LEGENDS
    \addlegendentry{Planck}
    \addlegendentry{Rayleigh-Jeans}
    \addlegendentry{Wien}
    \node[scale=1.] at (0.18*\xmax,0.01*\ymax) {$T=\SI{3000}{K}$};
    
  \end{loglogaxis}
\end{tikzpicture}



% BLACK BODY LOG-LOG - Rayleigh-Jeans / Wien
\begin{tikzpicture}
  \def\N{40}
  \def\xmin{2e2}
  \def\xmax{2e6}
  \def\ymin{1e-3}
  \def\ymax{1e7}
  \begin{loglogaxis}[every axis plot post/.append style={
               mark=none,domain=\xmin:\xmax,samples=\N,smooth},
               xmin=\xmin, xmax=(1.01*\xmax),
               ymin=\ymin, ymax=\ymax,
               restrict y to domain=0.1*\ymin:\ymax,
               log basis y=10,
               axis line style=thick,
               tick style={black,thick},
               ticklabel style={scale=0.8},
               %ticks=none,
               xlabel={Wavelength $\lambda$ [nm]},
               ylabel={Power $P$ [kW/sr\,m$^2$\,nm]},
               xlabel style={at={(rel axis cs:0.5,0)},below=8pt},
               ylabel style={above=-2pt},
               width=8cm, height=6cm,
               axis line on top
              ]
    
    % RAINBOW
    \shade[shading=rainbow,shading angle=90,opacity=0.4] (380,\ymin) rectangle (740,\ymax);
  	
    % PLANCK
    \addplot[very thick,black] {planck(x, 100)};
    \addplot[very thick,red]   {planck(x, 300)};
    \addplot[very thick,blue]  {planck(x, 800)};
    \addplot[dashed,thick,black] {rayleighjeans(x,100)};
    \addplot[dashed,thick,red]   {rayleighjeans(x,300)};
    \addplot[dashed,thick,blue]  {rayleighjeans(x,800)};
    \addplot[dotted,thick,black] {wien(x,100)};
    \addplot[dotted,thick,red]   {wien(x,300)};
    \addplot[dotted,thick,blue]  {wien(x,800)};
    
  \end{loglogaxis}
\end{tikzpicture}



\end{document}
