Pgfplots fillbetween 和 Tikz \shade

Pgfplots fillbetween 和 Tikz \shade

我正在尝试替换这个 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}

普朗克与彩虹

带有阴影的彩虹回答

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

在此处输入图片描述

如何“混合” tikz 和 pgfplots 代码?

非常感谢!

答案1

shading可以或多或少地代替fill,所以我对你上一个问题的回答Tikz 中带有“彩虹”的普朗克黑体曲线可以轻松修改,你只需要

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

而不是我在那里使用的。修改为domain正确的内容。

在此处输入图片描述

(顺便说一句,你似乎创建了两个帐户,我认为你可以将它们合并: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}

答案2

像这样?

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

在此处输入图片描述

相关内容