2

I'd like to use a colourmap like hot2 in this plot, where red occurs at x=0, and green occurs at x=1, but I can't find any way of doing it.

Here's what I have so far:

    \begin{tikzpicture}
            \begin{axis}[
             axis lines=left,
             grid=major,
             no marks,
             xmin=0, xmax=1, xlabel=$E$,
             ymin=0, ymax=1, ylabel=$\lambda$, ylabel style={rotate=-90}
             ]
            \addplot+[smooth,blue,name path=A] {1 - (1 - x)^2}; % actual curve
            \addplot+[draw=none,name path=B] {0};     % “fictional” curve
            \addplot+[green] fill between[of=A and B,soft clip={domain=0:1}]; % filling
      \end{axis}
    \end{tikzpicture}

Current

1 Answer 1

2

Welcome to TeX-SE! We usually begin our examples with \documentclass, end them with \end{document} and do not put non-standard characters in the code that prevents others from copying it. The following is an example of an MWE.

\documentclass[tikz,border=3.14mm]{standalone} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.16} 
\newsavebox\backbox
\pgfplotscolormaptoshadingspec{hot}{7cm}\result
\def\tempb{\pgfdeclarehorizontalshading{tempshading}{7cm}}%
% where '\result' is inserted as last argument:
\expandafter\tempb\expandafter{\result}%
\sbox\backbox{\pgfuseshading{tempshading}}%
\begin{document} 
  \begin{tikzpicture}
            \begin{axis}[set layers,view={90}{0},
             axis lines=left,
             grid=major,
             no marks,
             xmin=0, xmax=1, xlabel=$E$,
             ymin=0, ymax=1, ylabel=$\lambda$, ylabel style={rotate=-90}
             ]
            \addplot+[smooth,blue] {1 - (1 - x)^2}; % actual curve
            \begin{pgfonlayer}{pre main}
            \clip plot[variable=\x,samples=25,domain=0:1] (\x,{1 - (1 - \x)^2})
            |-cycle;
            \node at (0.5,0.5){\usebox\backbox};
            \end{pgfonlayer}
         % filling
      \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

9
  • Perfect thank you! Commented Apr 4, 2019 at 18:02
  • It works , but I do get an error: ! Undefined control sequence. <argument> \backbox l.41 \sbox\backbox{\pgfuseshading{tempshading}} % ? Commented Apr 4, 2019 at 18:12
  • 1
    @JordanMackie Sorry, these statements seem to contradict each other: "it works" and "I get an error". I get this very output from running pdflatex on the above code, of course without error message.
    – user121799
    Commented Apr 4, 2019 at 18:44
  • It does produce the same output, but compilation always trips up on that error, so it's not a major Commented Apr 4, 2019 at 22:01
  • 1
    @JordanMackie An error is major, but I do not get one if I compile the above on an updated TeXLive 2018 distribution with pdflatex. Which TeX installation and compiler do you use?
    – user121799
    Commented Apr 4, 2019 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .