Draw one function, varying color by (gradient) using another function's value












5















I'm trying to draw something in TikZ where I want to vary the draw color.



E.g. I'm drawing this line



documentclass[tikz]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
draw plot[variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
end{tikzpicture}
end{document}


enter image description here



But now I want the color to indicate the value of a function, e.g. c = x2.



Edit:
With x2 this could then look like:
enter image description here










share|improve this question





























    5















    I'm trying to draw something in TikZ where I want to vary the draw color.



    E.g. I'm drawing this line



    documentclass[tikz]{standalone}
    usetikzlibrary{intersections}
    begin{document}
    begin{tikzpicture}
    draw plot[variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
    end{tikzpicture}
    end{document}


    enter image description here



    But now I want the color to indicate the value of a function, e.g. c = x2.



    Edit:
    With x2 this could then look like:
    enter image description here










    share|improve this question



























      5












      5








      5








      I'm trying to draw something in TikZ where I want to vary the draw color.



      E.g. I'm drawing this line



      documentclass[tikz]{standalone}
      usetikzlibrary{intersections}
      begin{document}
      begin{tikzpicture}
      draw plot[variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
      end{tikzpicture}
      end{document}


      enter image description here



      But now I want the color to indicate the value of a function, e.g. c = x2.



      Edit:
      With x2 this could then look like:
      enter image description here










      share|improve this question
















      I'm trying to draw something in TikZ where I want to vary the draw color.



      E.g. I'm drawing this line



      documentclass[tikz]{standalone}
      usetikzlibrary{intersections}
      begin{document}
      begin{tikzpicture}
      draw plot[variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
      end{tikzpicture}
      end{document}


      enter image description here



      But now I want the color to indicate the value of a function, e.g. c = x2.



      Edit:
      With x2 this could then look like:
      enter image description here







      tikz-pgf color






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 12 hours ago







      sheß

















      asked 14 hours ago









      sheßsheß

      1,75511428




      1,75511428






















          1 Answer
          1






          active

          oldest

          votes


















          4














          Something like this may be:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          begin{document}
          begin{tikzpicture}
          begin{axis}
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}
          end{tikzpicture}
          end{document}


          I just changed the draw environment with addplot within an axis environment. This will give you:



          enter image description here



          Update Fix with colormaps. By utilising the colormaps tikz library you can set the desired color map and obtain what you desire. As in:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          usepgfplotslibrary{colormaps}
          % Note that this is the colormap definition. You can play with this however you want. Fun fact: this color map also includes 8bit color code definition. Which can be defined using rgb255 = {value,value,value}.
          pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(red) rgb=(0,0,1)}}
          begin{document}
          begin{tikzpicture}
          begin{axis}[point meta = y, colormap name={CM}]
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}

          end{tikzpicture}
          end{document}


          which will give you:



          enter image description here



          Update Credits goes to @marmot.



          You can an inline function in point meta definition to customise your colormap implicitly using an explicit function (see @marmot's comments).



          documentclass[tikz]{standalone}
          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}
          [ colormap/hot] addplot [point meta = x*x*x,mesh, samples=100,domain=-10:10] {sin(deg(x))+0.6*x};
          end{axis}
          end{tikzpicture}
          end{document}


          Here, I used cubic function for manipulating the color map. This will give



          enter image description here






          share|improve this answer





















          • 2





            Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

            – sheß
            12 hours ago






          • 1





            clear thanks I will try to cook up something

            – Raaja
            12 hours ago






          • 1





            @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

            – Raaja
            12 hours ago






          • 1





            Done adding, lately, falcons are going well together with @marmot.

            – Raaja
            9 hours ago






          • 1





            @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

            – Raaja
            3 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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f477270%2fdraw-one-function-varying-color-by-gradient-using-another-functions-value%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









          4














          Something like this may be:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          begin{document}
          begin{tikzpicture}
          begin{axis}
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}
          end{tikzpicture}
          end{document}


          I just changed the draw environment with addplot within an axis environment. This will give you:



          enter image description here



          Update Fix with colormaps. By utilising the colormaps tikz library you can set the desired color map and obtain what you desire. As in:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          usepgfplotslibrary{colormaps}
          % Note that this is the colormap definition. You can play with this however you want. Fun fact: this color map also includes 8bit color code definition. Which can be defined using rgb255 = {value,value,value}.
          pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(red) rgb=(0,0,1)}}
          begin{document}
          begin{tikzpicture}
          begin{axis}[point meta = y, colormap name={CM}]
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}

          end{tikzpicture}
          end{document}


          which will give you:



          enter image description here



          Update Credits goes to @marmot.



          You can an inline function in point meta definition to customise your colormap implicitly using an explicit function (see @marmot's comments).



          documentclass[tikz]{standalone}
          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}
          [ colormap/hot] addplot [point meta = x*x*x,mesh, samples=100,domain=-10:10] {sin(deg(x))+0.6*x};
          end{axis}
          end{tikzpicture}
          end{document}


          Here, I used cubic function for manipulating the color map. This will give



          enter image description here






          share|improve this answer





















          • 2





            Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

            – sheß
            12 hours ago






          • 1





            clear thanks I will try to cook up something

            – Raaja
            12 hours ago






          • 1





            @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

            – Raaja
            12 hours ago






          • 1





            Done adding, lately, falcons are going well together with @marmot.

            – Raaja
            9 hours ago






          • 1





            @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

            – Raaja
            3 hours ago
















          4














          Something like this may be:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          begin{document}
          begin{tikzpicture}
          begin{axis}
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}
          end{tikzpicture}
          end{document}


          I just changed the draw environment with addplot within an axis environment. This will give you:



          enter image description here



          Update Fix with colormaps. By utilising the colormaps tikz library you can set the desired color map and obtain what you desire. As in:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          usepgfplotslibrary{colormaps}
          % Note that this is the colormap definition. You can play with this however you want. Fun fact: this color map also includes 8bit color code definition. Which can be defined using rgb255 = {value,value,value}.
          pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(red) rgb=(0,0,1)}}
          begin{document}
          begin{tikzpicture}
          begin{axis}[point meta = y, colormap name={CM}]
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}

          end{tikzpicture}
          end{document}


          which will give you:



          enter image description here



          Update Credits goes to @marmot.



          You can an inline function in point meta definition to customise your colormap implicitly using an explicit function (see @marmot's comments).



          documentclass[tikz]{standalone}
          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}
          [ colormap/hot] addplot [point meta = x*x*x,mesh, samples=100,domain=-10:10] {sin(deg(x))+0.6*x};
          end{axis}
          end{tikzpicture}
          end{document}


          Here, I used cubic function for manipulating the color map. This will give



          enter image description here






          share|improve this answer





















          • 2





            Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

            – sheß
            12 hours ago






          • 1





            clear thanks I will try to cook up something

            – Raaja
            12 hours ago






          • 1





            @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

            – Raaja
            12 hours ago






          • 1





            Done adding, lately, falcons are going well together with @marmot.

            – Raaja
            9 hours ago






          • 1





            @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

            – Raaja
            3 hours ago














          4












          4








          4







          Something like this may be:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          begin{document}
          begin{tikzpicture}
          begin{axis}
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}
          end{tikzpicture}
          end{document}


          I just changed the draw environment with addplot within an axis environment. This will give you:



          enter image description here



          Update Fix with colormaps. By utilising the colormaps tikz library you can set the desired color map and obtain what you desire. As in:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          usepgfplotslibrary{colormaps}
          % Note that this is the colormap definition. You can play with this however you want. Fun fact: this color map also includes 8bit color code definition. Which can be defined using rgb255 = {value,value,value}.
          pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(red) rgb=(0,0,1)}}
          begin{document}
          begin{tikzpicture}
          begin{axis}[point meta = y, colormap name={CM}]
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}

          end{tikzpicture}
          end{document}


          which will give you:



          enter image description here



          Update Credits goes to @marmot.



          You can an inline function in point meta definition to customise your colormap implicitly using an explicit function (see @marmot's comments).



          documentclass[tikz]{standalone}
          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}
          [ colormap/hot] addplot [point meta = x*x*x,mesh, samples=100,domain=-10:10] {sin(deg(x))+0.6*x};
          end{axis}
          end{tikzpicture}
          end{document}


          Here, I used cubic function for manipulating the color map. This will give



          enter image description here






          share|improve this answer















          Something like this may be:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          begin{document}
          begin{tikzpicture}
          begin{axis}
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}
          end{tikzpicture}
          end{document}


          I just changed the draw environment with addplot within an axis environment. This will give you:



          enter image description here



          Update Fix with colormaps. By utilising the colormaps tikz library you can set the desired color map and obtain what you desire. As in:



          documentclass[tikz]{standalone}
          usepackage{pgfplots}
          usepgfplotslibrary{colormaps}
          % Note that this is the colormap definition. You can play with this however you want. Fun fact: this color map also includes 8bit color code definition. Which can be defined using rgb255 = {value,value,value}.
          pgfplotsset{colormap={CM}{rgb=(0,0,1) color=(red) rgb=(0,0,1)}}
          begin{document}
          begin{tikzpicture}
          begin{axis}[point meta = y, colormap name={CM}]
          addplot [mesh, variable=x, samples=100,domain=-10:10] ({x},{sin(deg(x))+0.6*x});
          end{axis}

          end{tikzpicture}
          end{document}


          which will give you:



          enter image description here



          Update Credits goes to @marmot.



          You can an inline function in point meta definition to customise your colormap implicitly using an explicit function (see @marmot's comments).



          documentclass[tikz]{standalone}
          usepackage{pgfplots}

          begin{document}
          begin{tikzpicture}
          begin{axis}
          [ colormap/hot] addplot [point meta = x*x*x,mesh, samples=100,domain=-10:10] {sin(deg(x))+0.6*x};
          end{axis}
          end{tikzpicture}
          end{document}


          Here, I used cubic function for manipulating the color map. This will give



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 9 hours ago

























          answered 13 hours ago









          RaajaRaaja

          4,30121138




          4,30121138








          • 2





            Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

            – sheß
            12 hours ago






          • 1





            clear thanks I will try to cook up something

            – Raaja
            12 hours ago






          • 1





            @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

            – Raaja
            12 hours ago






          • 1





            Done adding, lately, falcons are going well together with @marmot.

            – Raaja
            9 hours ago






          • 1





            @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

            – Raaja
            3 hours ago














          • 2





            Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

            – sheß
            12 hours ago






          • 1





            clear thanks I will try to cook up something

            – Raaja
            12 hours ago






          • 1





            @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

            – Raaja
            12 hours ago






          • 1





            Done adding, lately, falcons are going well together with @marmot.

            – Raaja
            9 hours ago






          • 1





            @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

            – Raaja
            3 hours ago








          2




          2





          Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

          – sheß
          12 hours ago





          Thanks, but I think this misses the bit that the color gradient should depict this a function, (in my question i used the example of x^2)

          – sheß
          12 hours ago




          1




          1





          clear thanks I will try to cook up something

          – Raaja
          12 hours ago





          clear thanks I will try to cook up something

          – Raaja
          12 hours ago




          1




          1





          @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

          – Raaja
          12 hours ago





          @sheß OOps, in that case, I will wait for some our in house TikZperts to answer your question ;)

          – Raaja
          12 hours ago




          1




          1





          Done adding, lately, falcons are going well together with @marmot.

          – Raaja
          9 hours ago





          Done adding, lately, falcons are going well together with @marmot.

          – Raaja
          9 hours ago




          1




          1





          @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

          – Raaja
          3 hours ago





          @sheB as much as it is nice to remove them, I would prefer to keep them as it gives a chronological evolution.

          – Raaja
          3 hours ago


















          draft saved

          draft discarded




















































          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%2f477270%2fdraw-one-function-varying-color-by-gradient-using-another-functions-value%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

          Paul Cézanne

          UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

          Angular material date-picker (MatDatepicker) auto completes the date on focus out