Fill area under curve using colourmap and Tikz












1















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










share|improve this question







New contributor




Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1















    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










    share|improve this question







    New contributor




    Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1


      1






      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










      share|improve this question







      New contributor




      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      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







      tikz-pgf graphics tikz-styles






      share|improve this question







      New contributor




      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 12 hours ago









      Jordan MackieJordan Mackie

      1084




      1084




      New contributor




      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Jordan Mackie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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}
          newsaveboxbackbox
          pgfplotscolormaptoshadingspec{hot}{7cm}result
          deftempb{pgfdeclarehorizontalshading{tempshading}{7cm}}%
          % where 'result' is inserted as last argument:
          expandaftertempbexpandafter{result}%
          sboxbackbox{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){useboxbackbox};
          end{pgfonlayer}
          % filling
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer
























          • Perfect thank you!

            – Jordan Mackie
            11 hours ago











          • It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

            – Jordan Mackie
            11 hours ago








          • 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.

            – marmot
            11 hours ago











          • It does produce the same output, but compilation always trips up on that error, so it's not a major

            – Jordan Mackie
            7 hours ago











          • @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?

            – marmot
            7 hours ago












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Jordan Mackie is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483209%2ffill-area-under-curve-using-colourmap-and-tikz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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}
          newsaveboxbackbox
          pgfplotscolormaptoshadingspec{hot}{7cm}result
          deftempb{pgfdeclarehorizontalshading{tempshading}{7cm}}%
          % where 'result' is inserted as last argument:
          expandaftertempbexpandafter{result}%
          sboxbackbox{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){useboxbackbox};
          end{pgfonlayer}
          % filling
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer
























          • Perfect thank you!

            – Jordan Mackie
            11 hours ago











          • It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

            – Jordan Mackie
            11 hours ago








          • 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.

            – marmot
            11 hours ago











          • It does produce the same output, but compilation always trips up on that error, so it's not a major

            – Jordan Mackie
            7 hours ago











          • @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?

            – marmot
            7 hours ago
















          1














          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}
          newsaveboxbackbox
          pgfplotscolormaptoshadingspec{hot}{7cm}result
          deftempb{pgfdeclarehorizontalshading{tempshading}{7cm}}%
          % where 'result' is inserted as last argument:
          expandaftertempbexpandafter{result}%
          sboxbackbox{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){useboxbackbox};
          end{pgfonlayer}
          % filling
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer
























          • Perfect thank you!

            – Jordan Mackie
            11 hours ago











          • It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

            – Jordan Mackie
            11 hours ago








          • 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.

            – marmot
            11 hours ago











          • It does produce the same output, but compilation always trips up on that error, so it's not a major

            – Jordan Mackie
            7 hours ago











          • @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?

            – marmot
            7 hours ago














          1












          1








          1







          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}
          newsaveboxbackbox
          pgfplotscolormaptoshadingspec{hot}{7cm}result
          deftempb{pgfdeclarehorizontalshading{tempshading}{7cm}}%
          % where 'result' is inserted as last argument:
          expandaftertempbexpandafter{result}%
          sboxbackbox{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){useboxbackbox};
          end{pgfonlayer}
          % filling
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer













          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}
          newsaveboxbackbox
          pgfplotscolormaptoshadingspec{hot}{7cm}result
          deftempb{pgfdeclarehorizontalshading{tempshading}{7cm}}%
          % where 'result' is inserted as last argument:
          expandaftertempbexpandafter{result}%
          sboxbackbox{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){useboxbackbox};
          end{pgfonlayer}
          % filling
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 hours ago









          marmotmarmot

          114k5145276




          114k5145276













          • Perfect thank you!

            – Jordan Mackie
            11 hours ago











          • It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

            – Jordan Mackie
            11 hours ago








          • 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.

            – marmot
            11 hours ago











          • It does produce the same output, but compilation always trips up on that error, so it's not a major

            – Jordan Mackie
            7 hours ago











          • @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?

            – marmot
            7 hours ago



















          • Perfect thank you!

            – Jordan Mackie
            11 hours ago











          • It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

            – Jordan Mackie
            11 hours ago








          • 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.

            – marmot
            11 hours ago











          • It does produce the same output, but compilation always trips up on that error, so it's not a major

            – Jordan Mackie
            7 hours ago











          • @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?

            – marmot
            7 hours ago

















          Perfect thank you!

          – Jordan Mackie
          11 hours ago





          Perfect thank you!

          – Jordan Mackie
          11 hours ago













          It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

          – Jordan Mackie
          11 hours ago







          It works , but I do get an error: ! Undefined control sequence. <argument> backbox l.41 sboxbackbox{pgfuseshading{tempshading}} % ?

          – Jordan Mackie
          11 hours ago






          1




          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.

          – marmot
          11 hours ago





          @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.

          – marmot
          11 hours ago













          It does produce the same output, but compilation always trips up on that error, so it's not a major

          – Jordan Mackie
          7 hours ago





          It does produce the same output, but compilation always trips up on that error, so it's not a major

          – Jordan Mackie
          7 hours ago













          @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?

          – marmot
          7 hours ago





          @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?

          – marmot
          7 hours ago










          Jordan Mackie is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Jordan Mackie is a new contributor. Be nice, and check out our Code of Conduct.













          Jordan Mackie is a new contributor. Be nice, and check out our Code of Conduct.












          Jordan Mackie is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483209%2ffill-area-under-curve-using-colourmap-and-tikz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks