3

I am trying to replace the rainbow in this MWE

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfmath}
\usepackage{amsmath}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}


\usepackage[%
        %decimalsymbol=comma,
        locale=DE,
]{siunitx}

\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat=1.16}

\begin{document}
    \begin{tikzpicture}[samples=200, scale=1.15,declare function={
        planck(\x,\T)=(374177152466412/\x^5)/(exp(14387.77/(\x*\T))-1);
    }]
    \begin{axis}[
    xmin=0,
    xmax=3,
    xlabel={$\omega$ [\si{\hertz}]},
    ymin=0,
    ylabel={$\rho (\omega; T)$ [\si{\joule\per\cubic\meter}]},
    ytick=\empty,
    no markers,
    grid=both,
    domain=0.1:3,
    ]
    \addplot+ [forget plot,name path=A] {planck(x,6000)};
    \addplot [forget plot,name path=B,samples=2] {0};
%-------------------------------
%   add shading code here...
%-------------------------------
    \addplot [forget plot,blue] fill between [of=A and B,soft clip={domain=.4:.47}];
    \addplot [forget plot,green] fill between [of=A and B,soft clip={domain=.47:.535}];
    \addplot [forget plot,yellow] fill between [of=A and B,soft clip={domain=.535:.6}];   
    \addplot [forget plot,orange] fill between [of=A and B,soft clip={domain=.6:.66}];             
    \addplot [forget plot,red] fill between [of=A and B,soft clip={domain=.66:.72}];

    \pgfplotsinvokeforeach{3000, 4000, 5000, 6000}
    {
        \addplot {planck(x,#1)};
        \addlegendentryexpanded{$T = #1\,\si{\kelvin}$}
    }
    \end{axis}
    \end{tikzpicture}
\end{document}

Planck with rainbow

with the shaded rainbow from this answer

\documentclass{article}
\usepackage[named]{xcolor}
\usepackage{pgffor}
\usepackage{tikz}
\usetikzlibrary{shadings}

\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)}
\begin{document}
\begin{tikzpicture}
\shade[shading=rainbow,shading angle=270] (0,0) rectangle (5cm,\textheight);
\end{tikzpicture}
\end{document}

enter image description here

How is it possible to "mix" the tikz and pgfplots code?

Thank you very much!

7

shading can be used more or less instead of fill, so my answer to your previous question Planck's blackbody curve with "rainbow" in Tikz can be easily modified, you just need

\addplot [shading=rainbow, shading angle=90, forget plot, draw=none, domain=5:10] {planck(x,5000)} \closedcycle;

instead of what I used there. Modify the domain to whatever is correct.

enter image description here

(By the way, you seem to have made two accounts, I think you can have them merged: https://tex.stackexchange.com/help/merging-accounts)

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usetikzlibrary{shadings}

\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)}

\begin{document}
    \begin{tikzpicture}[
      samples=100,
      declare function={
        planck(\x,\T)=(\x^3)/((pi^2)*(exp(2000*\x/(\T))-1));
      }]
    \begin{axis}[
        xmin=0,
        xlabel={$\omega$ [\si{\hertz}]},
        ymin=0,
        ymax=pi,
        ylabel={$\rho (\omega; T)$ [\si{\joule\per\cubic\meter}]},
        ytick=\empty,
        no markers,
        grid=both,domain=0.1:40,
        style={ultra thick}]

      \addplot [shading=rainbow, shading angle=90, forget plot, draw=none, domain=5:10] {planck(x,5000)} \closedcycle;

    \pgfplotsinvokeforeach{3000, 4000, 5000}
    {
        \addplot {planck(x,#1)};
        \addlegendentryexpanded{$T = #1 [\si{\kelvin}]$}
    }

    \end{axis}
    \end{tikzpicture}
\end{document}
1
  • Thank you very much! – vulcano9 Jul 23 '19 at 19:00
3

Like this?

    \documentclass{standalone}
    \usepackage{pgfplots}
    \usepackage{pgfmath}
    \usepackage{amsmath}
    \usepackage[ngerman]{babel}
    \usepackage[utf8]{inputenc}


    \usepackage[%
            %decimalsymbol=comma,
            locale=DE,
    ]{siunitx}

    \usepgfplotslibrary{fillbetween}
    \usetikzlibrary{shadings}
    \pgfplotsset{compat=1.16}

    \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)}

    \begin{document}
        \begin{tikzpicture}[samples=200, scale=1.15,declare function={
            planck(\x,\T)=(374177152466412/\x^5)/(exp(14387.77/(\x*\T))-1);
        }]
        \begin{axis}[
        xmin=0,
        xmax=3,
        xlabel={$\omega$ [\si{\hertz}]},
        ymin=0,
        ylabel={$\rho (\omega; T)$ [\si{\joule\per\cubic\meter}]},
        ytick=\empty,
        no markers,
        grid=both,
        domain=0.1:3,
        ]
        \addplot+ [forget plot,name path=A] {planck(x,6000)};
        \addplot [forget plot,name path=B,samples=2] {0};
    %-------------------------------
    %   add shading code here...
    %-------------------------------
        \addplot [forget plot,shading=rainbow,shading angle=270] 
fill between [of=A and B,soft clip={domain=.4:.72}];
     %   \addplot [forget plot,green] fill between [of=A and B,soft clip={domain=.47:.535}];
    %    \addplot [forget plot,yellow] fill between [of=A and B,soft clip={domain=.535:.6}];   
    %    \addplot [forget plot,orange] fill between [of=A and B,soft clip={domain=.6:.66}];             
    %    \addplot [forget plot,red] fill between [of=A and B,soft clip={domain=.66:.72}];

        \pgfplotsinvokeforeach{3000, 4000, 5000, 6000}
        {
            \addplot {planck(x,#1)};
            \addlegendentryexpanded{$T = #1\,\si{\kelvin}$}
        }
        \end{axis}
        \end{tikzpicture}
    \end{document}

enter image description here

1
  • Thank you guys! – vulcano9 Jul 23 '19 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.