tikz declare function with multiple outputsContour plot of arbitrary R^3 function without gnuplotHow to plot this function containing ceiling in TikZ?tikz declare function and babel french optionDeclare function for tikzpictureNumerical conditional within tikz keys?pgfplots: Plot inverse function (function of y)Location and size of pgf plot axis in a tikzpicture - with tikz positioning library?Why do I get an extra white page before my TikZ picture?How to prevent rounded and duplicated tick labels in pgfplots with fixed precision?Drawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themHow to draw a square and its diagonals with arrows?

Definition of "worst point one percent"?

Can you marry a girl in Stardew Valley if you are a girl?

Why do aircraft cockpit displays use uppercase fonts?

Any real contribution of functional analysis to quantum theory as a branch of physics?

What is the narrative difference between a Charisma and Wisdom saving throw?

Why don't the absolute value functions in C accept const inputs?

Students using the same flawed online solution sheet as the grading TA

What would you call this scale?

Can I ignore an open source license if I checkout a version that was released prior to the code having any license?

How can I force a bank to close my account with them?

Is it possible for a tiger's tail to be taken off and replaced with a living cobra, with both creatures still alive?

Is it principled to tip less if a pricey restaurant doesn't accept Visa or Mastercard?

Will the same Javascript fetched by HTTP and HTTPS be cached separately by the browser?

How to deal with this fundamental problem with the advice: "Don't trust obscure PHP libraries that nobody uses!"?

What does "x employee is no longer employed by XYZ company" mean?

I shift the source code, you shift the input!

If a problem is in P solved via dynamic programming, is it also in NP?

How to calculate my anticipated peak amperage load?

Why is reinforcement learning not the answer to AGI?

how technically soft landing works without air on moon?

Where does this plural come from?

Story ID: plugging vacuum leak with one's butt

Short story: Man gains X-ray vision, cheats at cards, sees a clot in his blood

Have spacecraft photographed each other beyond Earth orbit?



tikz declare function with multiple outputs


Contour plot of arbitrary R^3 function without gnuplotHow to plot this function containing ceiling in TikZ?tikz declare function and babel french optionDeclare function for tikzpictureNumerical conditional within tikz keys?pgfplots: Plot inverse function (function of y)Location and size of pgf plot axis in a tikzpicture - with tikz positioning library?Why do I get an extra white page before my TikZ picture?How to prevent rounded and duplicated tick labels in pgfplots with fixed precision?Drawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themHow to draw a square and its diagonals with arrows?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4


















Is it possible to declare a function in tikz or pgfplots with multiple outputs?



Consider the case when we want to plot samples from a probability distribution. Usually we could do something like



documentclassstandalone
usepackagetikz, pgfplots
begindocument
begintikzpicture[declare function=xfun(x)=x; yfun(y)=y;]
beginaxis
addplot [only marks, samples=50] (xfun(rnd), yfun(rnd));
endaxis
endtikzpicture
enddocument


However this only works when the probability distribution factorizes as p(x, y) = f(x) g(y), but I want to plot some pdfs that don't. I tried to do



documentclassstandalone
usepackagetikz, pgfplots
begindocument
begintikzpicture[declare function=myfun(x,y)=x+y, x-y;]
beginaxis
addplot [only marks, samples=50] (myfun(rnd, rnd));
endaxis
endtikzpicture
enddocument


but that doesn't work.










share|improve this question

































    4


















    Is it possible to declare a function in tikz or pgfplots with multiple outputs?



    Consider the case when we want to plot samples from a probability distribution. Usually we could do something like



    documentclassstandalone
    usepackagetikz, pgfplots
    begindocument
    begintikzpicture[declare function=xfun(x)=x; yfun(y)=y;]
    beginaxis
    addplot [only marks, samples=50] (xfun(rnd), yfun(rnd));
    endaxis
    endtikzpicture
    enddocument


    However this only works when the probability distribution factorizes as p(x, y) = f(x) g(y), but I want to plot some pdfs that don't. I tried to do



    documentclassstandalone
    usepackagetikz, pgfplots
    begindocument
    begintikzpicture[declare function=myfun(x,y)=x+y, x-y;]
    beginaxis
    addplot [only marks, samples=50] (myfun(rnd, rnd));
    endaxis
    endtikzpicture
    enddocument


    but that doesn't work.










    share|improve this question





























      4













      4









      4








      Is it possible to declare a function in tikz or pgfplots with multiple outputs?



      Consider the case when we want to plot samples from a probability distribution. Usually we could do something like



      documentclassstandalone
      usepackagetikz, pgfplots
      begindocument
      begintikzpicture[declare function=xfun(x)=x; yfun(y)=y;]
      beginaxis
      addplot [only marks, samples=50] (xfun(rnd), yfun(rnd));
      endaxis
      endtikzpicture
      enddocument


      However this only works when the probability distribution factorizes as p(x, y) = f(x) g(y), but I want to plot some pdfs that don't. I tried to do



      documentclassstandalone
      usepackagetikz, pgfplots
      begindocument
      begintikzpicture[declare function=myfun(x,y)=x+y, x-y;]
      beginaxis
      addplot [only marks, samples=50] (myfun(rnd, rnd));
      endaxis
      endtikzpicture
      enddocument


      but that doesn't work.










      share|improve this question
















      Is it possible to declare a function in tikz or pgfplots with multiple outputs?



      Consider the case when we want to plot samples from a probability distribution. Usually we could do something like



      documentclassstandalone
      usepackagetikz, pgfplots
      begindocument
      begintikzpicture[declare function=xfun(x)=x; yfun(y)=y;]
      beginaxis
      addplot [only marks, samples=50] (xfun(rnd), yfun(rnd));
      endaxis
      endtikzpicture
      enddocument


      However this only works when the probability distribution factorizes as p(x, y) = f(x) g(y), but I want to plot some pdfs that don't. I tried to do



      documentclassstandalone
      usepackagetikz, pgfplots
      begindocument
      begintikzpicture[declare function=myfun(x,y)=x+y, x-y;]
      beginaxis
      addplot [only marks, samples=50] (myfun(rnd, rnd));
      endaxis
      endtikzpicture
      enddocument


      but that doesn't work.







      tikz-pgf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 30 at 17:04







      Hyperplane

















      asked Sep 30 at 14:38









      HyperplaneHyperplane

      2751 silver badge8 bronze badges




      2751 silver badge8 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          7



















          It is possible to declare such functions with pgfmathdeclarefunction. Unfortunately, pgfplots won't parse the results in the way one wants, so one needs to extract the x and y components. The good news is that this can be done by appropriately defined functions, too. They are called xcomp2 and ycomp2 since they are the 2d counterparts of the functions xcomp3 and ycomp3 from this experimental library. To illustrate things, I declared a function myfun with myfun(x,y)=(x+y,x-y),



          pgfmathdeclarefunctionmyfun2% 
          begingroup%
          pgfmathsetmacromyx#1+#2%
          pgfmathsetmacromyy#1-#2%
          edefpgfmathresultmyxmyy%
          pgfmathsmugglepgfmathresultendgroup


          It is used in the MWE



          documentclass[tikz,border=3mm]standalone
          usepackagepgfplots
          pgfplotssetcompat=1.16
          begindocument
          pgfmathdeclarefunctionmyfun2%
          begingroup%
          pgfmathsetmacromyx#1+#2%
          pgfmathsetmacromyy#1-#2%
          edefpgfmathresultmyxmyy%
          pgfmathsmugglepgfmathresultendgroup
          pgfmathdeclarefunctionxcomp22% x component of a 2-vector
          begingroup%
          pgfmathparse#1%
          pgfmathsmugglepgfmathresultendgroup
          pgfmathdeclarefunctionycomp22% y component of a 2-vector
          begingroup%
          pgfmathparse#2%
          pgfmathsmugglepgfmathresultendgroup
          begintikzpicture
          beginaxis
          addplot [only marks, samples=50] (xcomp2(myfun(rnd,rnd)),ycomp2(myfun(rnd,rnd)));
          endaxis
          endtikzpicture
          enddocument


          enter image description here



          P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).






          share|improve this answer



























          • First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

            – Hyperplane
            Sep 30 at 17:16











          • @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

            – Schrödinger's cat
            Sep 30 at 17:22











          • @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

            – DJP
            Oct 1 at 12:21



















          0



















          Here's a possible implementation using the sagetex package:



          documentclass[border=5pt]standalone
          usepackagesagetex
          usepackage[usenames,dvipsnames]xcolor
          usepackagepgfplots
          pgfplotssetcompat=1.15
          begindocument
          beginsagesilent
          LowerX = 0
          UpperX = 2
          LowerY = -1
          UpperY = 1
          Scale = 1.2
          xscale=1
          yscale=1
          L = []
          ####### Create the points ###############
          for i in range(0,10):
          for j in range(0,10):
          r1 = random()
          r2 = random()
          L += [[r1+r2,r1-r2]]
          ##### Plot the points in tikz ###########
          output = r""
          output += r"begintikzpicture[scale=1]"
          output += r"beginaxis[xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
          output += r"addplot[red,only marks,mark options=mark size=.5pt] coordinates "
          for i in range(0,len(L)-1):
          output += r"(%f , %f) "%(L[i][0],L[i][1])
          output += r";"
          output += r"endaxis"
          output += r"endtikzpicture"
          endsagesilent
          sagestroutput
          enddocument


          The output, running in Cocalc is:
          enter image description here



          Since you're working with a CAS, SAGE has lots of different types of random numbers, see here.
          Note that the sagesilent environment lets you program in Python. The two results are being stored as a list of length 2 inside list L. After the list of points is created, it's just a matter of incorporating them into the tikzpicture. This needs to be done as a string as sagetex involves a 3 step compilation process: first LaTeX must compile, then Sage compiles, then the final compilation involves LaTeX plus SAGE output. If an output string wasn't used, then the first attempt to compile LaTeX would fail as it relies on SAGE results that it needs but doesn't yet have.



          The table of contents of the SAGE manual online; from here you can see that SAGE includes lots of open source programs including (quoting from link):



          ATLAS — Automatically Tuned Linear Algebra Software.
          BLAS — Basic Linear Algebra Subprograms.
          FLINT — C library for doing number theory.
          GAP — a system for computational discrete algebra, with particular emphasis on computational group theory.
          Maxima — system for symbolic and numerical computation.
          mpmath — a pure-Python library for multiprecision floating-point arithmetic.
          NumPy — numerical linear algebra and other numerical computing capabilities for Python.
          Pari/GP — a computer algebra system for fast computations in number theory.
          Pynac — a modified version of GiNaC that replaces the dependency on CLN by Python.
          R — a language and environment for statistical computing and graphics.
          And many more too numerous to list here.


          SAGE is not included with LaTeX, so you will either need to download a copy and install it to your computer locally OR, better yet, open a free Cocalc account and do your work in the cloud. In that case, you don't need SAGE on your computer but you will need access to the internet.






          share|improve this answer




























            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/4.0/"u003ecc by-sa 4.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%2f510418%2ftikz-declare-function-with-multiple-outputs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown


























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            7



















            It is possible to declare such functions with pgfmathdeclarefunction. Unfortunately, pgfplots won't parse the results in the way one wants, so one needs to extract the x and y components. The good news is that this can be done by appropriately defined functions, too. They are called xcomp2 and ycomp2 since they are the 2d counterparts of the functions xcomp3 and ycomp3 from this experimental library. To illustrate things, I declared a function myfun with myfun(x,y)=(x+y,x-y),



            pgfmathdeclarefunctionmyfun2% 
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup


            It is used in the MWE



            documentclass[tikz,border=3mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            pgfmathdeclarefunctionmyfun2%
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionxcomp22% x component of a 2-vector
            begingroup%
            pgfmathparse#1%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionycomp22% y component of a 2-vector
            begingroup%
            pgfmathparse#2%
            pgfmathsmugglepgfmathresultendgroup
            begintikzpicture
            beginaxis
            addplot [only marks, samples=50] (xcomp2(myfun(rnd,rnd)),ycomp2(myfun(rnd,rnd)));
            endaxis
            endtikzpicture
            enddocument


            enter image description here



            P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).






            share|improve this answer



























            • First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

              – Hyperplane
              Sep 30 at 17:16











            • @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

              – Schrödinger's cat
              Sep 30 at 17:22











            • @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

              – DJP
              Oct 1 at 12:21
















            7



















            It is possible to declare such functions with pgfmathdeclarefunction. Unfortunately, pgfplots won't parse the results in the way one wants, so one needs to extract the x and y components. The good news is that this can be done by appropriately defined functions, too. They are called xcomp2 and ycomp2 since they are the 2d counterparts of the functions xcomp3 and ycomp3 from this experimental library. To illustrate things, I declared a function myfun with myfun(x,y)=(x+y,x-y),



            pgfmathdeclarefunctionmyfun2% 
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup


            It is used in the MWE



            documentclass[tikz,border=3mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            pgfmathdeclarefunctionmyfun2%
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionxcomp22% x component of a 2-vector
            begingroup%
            pgfmathparse#1%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionycomp22% y component of a 2-vector
            begingroup%
            pgfmathparse#2%
            pgfmathsmugglepgfmathresultendgroup
            begintikzpicture
            beginaxis
            addplot [only marks, samples=50] (xcomp2(myfun(rnd,rnd)),ycomp2(myfun(rnd,rnd)));
            endaxis
            endtikzpicture
            enddocument


            enter image description here



            P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).






            share|improve this answer



























            • First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

              – Hyperplane
              Sep 30 at 17:16











            • @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

              – Schrödinger's cat
              Sep 30 at 17:22











            • @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

              – DJP
              Oct 1 at 12:21














            7















            7











            7









            It is possible to declare such functions with pgfmathdeclarefunction. Unfortunately, pgfplots won't parse the results in the way one wants, so one needs to extract the x and y components. The good news is that this can be done by appropriately defined functions, too. They are called xcomp2 and ycomp2 since they are the 2d counterparts of the functions xcomp3 and ycomp3 from this experimental library. To illustrate things, I declared a function myfun with myfun(x,y)=(x+y,x-y),



            pgfmathdeclarefunctionmyfun2% 
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup


            It is used in the MWE



            documentclass[tikz,border=3mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            pgfmathdeclarefunctionmyfun2%
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionxcomp22% x component of a 2-vector
            begingroup%
            pgfmathparse#1%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionycomp22% y component of a 2-vector
            begingroup%
            pgfmathparse#2%
            pgfmathsmugglepgfmathresultendgroup
            begintikzpicture
            beginaxis
            addplot [only marks, samples=50] (xcomp2(myfun(rnd,rnd)),ycomp2(myfun(rnd,rnd)));
            endaxis
            endtikzpicture
            enddocument


            enter image description here



            P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).






            share|improve this answer
















            It is possible to declare such functions with pgfmathdeclarefunction. Unfortunately, pgfplots won't parse the results in the way one wants, so one needs to extract the x and y components. The good news is that this can be done by appropriately defined functions, too. They are called xcomp2 and ycomp2 since they are the 2d counterparts of the functions xcomp3 and ycomp3 from this experimental library. To illustrate things, I declared a function myfun with myfun(x,y)=(x+y,x-y),



            pgfmathdeclarefunctionmyfun2% 
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup


            It is used in the MWE



            documentclass[tikz,border=3mm]standalone
            usepackagepgfplots
            pgfplotssetcompat=1.16
            begindocument
            pgfmathdeclarefunctionmyfun2%
            begingroup%
            pgfmathsetmacromyx#1+#2%
            pgfmathsetmacromyy#1-#2%
            edefpgfmathresultmyxmyy%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionxcomp22% x component of a 2-vector
            begingroup%
            pgfmathparse#1%
            pgfmathsmugglepgfmathresultendgroup
            pgfmathdeclarefunctionycomp22% y component of a 2-vector
            begingroup%
            pgfmathparse#2%
            pgfmathsmugglepgfmathresultendgroup
            begintikzpicture
            beginaxis
            addplot [only marks, samples=50] (xcomp2(myfun(rnd,rnd)),ycomp2(myfun(rnd,rnd)));
            endaxis
            endtikzpicture
            enddocument


            enter image description here



            P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).







            share|improve this answer















            share|improve this answer




            share|improve this answer








            edited Sep 30 at 17:42

























            answered Sep 30 at 16:22









            Schrödinger's catSchrödinger's cat

            31.2k2 gold badges45 silver badges72 bronze badges




            31.2k2 gold badges45 silver badges72 bronze badges















            • First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

              – Hyperplane
              Sep 30 at 17:16











            • @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

              – Schrödinger's cat
              Sep 30 at 17:22











            • @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

              – DJP
              Oct 1 at 12:21


















            • First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

              – Hyperplane
              Sep 30 at 17:16











            • @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

              – Schrödinger's cat
              Sep 30 at 17:22











            • @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

              – DJP
              Oct 1 at 12:21

















            First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

            – Hyperplane
            Sep 30 at 17:16





            First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuff pgfmathsmuggle to do the simplest things. I guess I should just do all plots in matplotlib in the future.... Really wish one could just use python code within a latex document... (i know pylatex exists but that's kinda different)

            – Hyperplane
            Sep 30 at 17:16













            @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

            – Schrödinger's cat
            Sep 30 at 17:22





            @Hyperplane pgfmathsmuggle is not really "shady", it helps keeping things tidy. You may ask why vector-valued functions are not supported "out of the box". The answer may be that no one made a feature request at the pgf github site.

            – Schrödinger's cat
            Sep 30 at 17:22













            @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

            – DJP
            Oct 1 at 12:21






            @Hyperplane You should look into the sagetex package. This gives you Python and a computer algebra system called SAGE. My answer to the problem Contour plot of arbitrary R^3 function without gnuplot used matplotlib. With a little more work you can push plots through to tikz as well: How to plot this function containing ceiling in TikZ?

            – DJP
            Oct 1 at 12:21














            0



















            Here's a possible implementation using the sagetex package:



            documentclass[border=5pt]standalone
            usepackagesagetex
            usepackage[usenames,dvipsnames]xcolor
            usepackagepgfplots
            pgfplotssetcompat=1.15
            begindocument
            beginsagesilent
            LowerX = 0
            UpperX = 2
            LowerY = -1
            UpperY = 1
            Scale = 1.2
            xscale=1
            yscale=1
            L = []
            ####### Create the points ###############
            for i in range(0,10):
            for j in range(0,10):
            r1 = random()
            r2 = random()
            L += [[r1+r2,r1-r2]]
            ##### Plot the points in tikz ###########
            output = r""
            output += r"begintikzpicture[scale=1]"
            output += r"beginaxis[xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
            output += r"addplot[red,only marks,mark options=mark size=.5pt] coordinates "
            for i in range(0,len(L)-1):
            output += r"(%f , %f) "%(L[i][0],L[i][1])
            output += r";"
            output += r"endaxis"
            output += r"endtikzpicture"
            endsagesilent
            sagestroutput
            enddocument


            The output, running in Cocalc is:
            enter image description here



            Since you're working with a CAS, SAGE has lots of different types of random numbers, see here.
            Note that the sagesilent environment lets you program in Python. The two results are being stored as a list of length 2 inside list L. After the list of points is created, it's just a matter of incorporating them into the tikzpicture. This needs to be done as a string as sagetex involves a 3 step compilation process: first LaTeX must compile, then Sage compiles, then the final compilation involves LaTeX plus SAGE output. If an output string wasn't used, then the first attempt to compile LaTeX would fail as it relies on SAGE results that it needs but doesn't yet have.



            The table of contents of the SAGE manual online; from here you can see that SAGE includes lots of open source programs including (quoting from link):



            ATLAS — Automatically Tuned Linear Algebra Software.
            BLAS — Basic Linear Algebra Subprograms.
            FLINT — C library for doing number theory.
            GAP — a system for computational discrete algebra, with particular emphasis on computational group theory.
            Maxima — system for symbolic and numerical computation.
            mpmath — a pure-Python library for multiprecision floating-point arithmetic.
            NumPy — numerical linear algebra and other numerical computing capabilities for Python.
            Pari/GP — a computer algebra system for fast computations in number theory.
            Pynac — a modified version of GiNaC that replaces the dependency on CLN by Python.
            R — a language and environment for statistical computing and graphics.
            And many more too numerous to list here.


            SAGE is not included with LaTeX, so you will either need to download a copy and install it to your computer locally OR, better yet, open a free Cocalc account and do your work in the cloud. In that case, you don't need SAGE on your computer but you will need access to the internet.






            share|improve this answer































              0



















              Here's a possible implementation using the sagetex package:



              documentclass[border=5pt]standalone
              usepackagesagetex
              usepackage[usenames,dvipsnames]xcolor
              usepackagepgfplots
              pgfplotssetcompat=1.15
              begindocument
              beginsagesilent
              LowerX = 0
              UpperX = 2
              LowerY = -1
              UpperY = 1
              Scale = 1.2
              xscale=1
              yscale=1
              L = []
              ####### Create the points ###############
              for i in range(0,10):
              for j in range(0,10):
              r1 = random()
              r2 = random()
              L += [[r1+r2,r1-r2]]
              ##### Plot the points in tikz ###########
              output = r""
              output += r"begintikzpicture[scale=1]"
              output += r"beginaxis[xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
              output += r"addplot[red,only marks,mark options=mark size=.5pt] coordinates "
              for i in range(0,len(L)-1):
              output += r"(%f , %f) "%(L[i][0],L[i][1])
              output += r";"
              output += r"endaxis"
              output += r"endtikzpicture"
              endsagesilent
              sagestroutput
              enddocument


              The output, running in Cocalc is:
              enter image description here



              Since you're working with a CAS, SAGE has lots of different types of random numbers, see here.
              Note that the sagesilent environment lets you program in Python. The two results are being stored as a list of length 2 inside list L. After the list of points is created, it's just a matter of incorporating them into the tikzpicture. This needs to be done as a string as sagetex involves a 3 step compilation process: first LaTeX must compile, then Sage compiles, then the final compilation involves LaTeX plus SAGE output. If an output string wasn't used, then the first attempt to compile LaTeX would fail as it relies on SAGE results that it needs but doesn't yet have.



              The table of contents of the SAGE manual online; from here you can see that SAGE includes lots of open source programs including (quoting from link):



              ATLAS — Automatically Tuned Linear Algebra Software.
              BLAS — Basic Linear Algebra Subprograms.
              FLINT — C library for doing number theory.
              GAP — a system for computational discrete algebra, with particular emphasis on computational group theory.
              Maxima — system for symbolic and numerical computation.
              mpmath — a pure-Python library for multiprecision floating-point arithmetic.
              NumPy — numerical linear algebra and other numerical computing capabilities for Python.
              Pari/GP — a computer algebra system for fast computations in number theory.
              Pynac — a modified version of GiNaC that replaces the dependency on CLN by Python.
              R — a language and environment for statistical computing and graphics.
              And many more too numerous to list here.


              SAGE is not included with LaTeX, so you will either need to download a copy and install it to your computer locally OR, better yet, open a free Cocalc account and do your work in the cloud. In that case, you don't need SAGE on your computer but you will need access to the internet.






              share|improve this answer





























                0















                0











                0









                Here's a possible implementation using the sagetex package:



                documentclass[border=5pt]standalone
                usepackagesagetex
                usepackage[usenames,dvipsnames]xcolor
                usepackagepgfplots
                pgfplotssetcompat=1.15
                begindocument
                beginsagesilent
                LowerX = 0
                UpperX = 2
                LowerY = -1
                UpperY = 1
                Scale = 1.2
                xscale=1
                yscale=1
                L = []
                ####### Create the points ###############
                for i in range(0,10):
                for j in range(0,10):
                r1 = random()
                r2 = random()
                L += [[r1+r2,r1-r2]]
                ##### Plot the points in tikz ###########
                output = r""
                output += r"begintikzpicture[scale=1]"
                output += r"beginaxis[xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
                output += r"addplot[red,only marks,mark options=mark size=.5pt] coordinates "
                for i in range(0,len(L)-1):
                output += r"(%f , %f) "%(L[i][0],L[i][1])
                output += r";"
                output += r"endaxis"
                output += r"endtikzpicture"
                endsagesilent
                sagestroutput
                enddocument


                The output, running in Cocalc is:
                enter image description here



                Since you're working with a CAS, SAGE has lots of different types of random numbers, see here.
                Note that the sagesilent environment lets you program in Python. The two results are being stored as a list of length 2 inside list L. After the list of points is created, it's just a matter of incorporating them into the tikzpicture. This needs to be done as a string as sagetex involves a 3 step compilation process: first LaTeX must compile, then Sage compiles, then the final compilation involves LaTeX plus SAGE output. If an output string wasn't used, then the first attempt to compile LaTeX would fail as it relies on SAGE results that it needs but doesn't yet have.



                The table of contents of the SAGE manual online; from here you can see that SAGE includes lots of open source programs including (quoting from link):



                ATLAS — Automatically Tuned Linear Algebra Software.
                BLAS — Basic Linear Algebra Subprograms.
                FLINT — C library for doing number theory.
                GAP — a system for computational discrete algebra, with particular emphasis on computational group theory.
                Maxima — system for symbolic and numerical computation.
                mpmath — a pure-Python library for multiprecision floating-point arithmetic.
                NumPy — numerical linear algebra and other numerical computing capabilities for Python.
                Pari/GP — a computer algebra system for fast computations in number theory.
                Pynac — a modified version of GiNaC that replaces the dependency on CLN by Python.
                R — a language and environment for statistical computing and graphics.
                And many more too numerous to list here.


                SAGE is not included with LaTeX, so you will either need to download a copy and install it to your computer locally OR, better yet, open a free Cocalc account and do your work in the cloud. In that case, you don't need SAGE on your computer but you will need access to the internet.






                share|improve this answer
















                Here's a possible implementation using the sagetex package:



                documentclass[border=5pt]standalone
                usepackagesagetex
                usepackage[usenames,dvipsnames]xcolor
                usepackagepgfplots
                pgfplotssetcompat=1.15
                begindocument
                beginsagesilent
                LowerX = 0
                UpperX = 2
                LowerY = -1
                UpperY = 1
                Scale = 1.2
                xscale=1
                yscale=1
                L = []
                ####### Create the points ###############
                for i in range(0,10):
                for j in range(0,10):
                r1 = random()
                r2 = random()
                L += [[r1+r2,r1-r2]]
                ##### Plot the points in tikz ###########
                output = r""
                output += r"begintikzpicture[scale=1]"
                output += r"beginaxis[xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
                output += r"addplot[red,only marks,mark options=mark size=.5pt] coordinates "
                for i in range(0,len(L)-1):
                output += r"(%f , %f) "%(L[i][0],L[i][1])
                output += r";"
                output += r"endaxis"
                output += r"endtikzpicture"
                endsagesilent
                sagestroutput
                enddocument


                The output, running in Cocalc is:
                enter image description here



                Since you're working with a CAS, SAGE has lots of different types of random numbers, see here.
                Note that the sagesilent environment lets you program in Python. The two results are being stored as a list of length 2 inside list L. After the list of points is created, it's just a matter of incorporating them into the tikzpicture. This needs to be done as a string as sagetex involves a 3 step compilation process: first LaTeX must compile, then Sage compiles, then the final compilation involves LaTeX plus SAGE output. If an output string wasn't used, then the first attempt to compile LaTeX would fail as it relies on SAGE results that it needs but doesn't yet have.



                The table of contents of the SAGE manual online; from here you can see that SAGE includes lots of open source programs including (quoting from link):



                ATLAS — Automatically Tuned Linear Algebra Software.
                BLAS — Basic Linear Algebra Subprograms.
                FLINT — C library for doing number theory.
                GAP — a system for computational discrete algebra, with particular emphasis on computational group theory.
                Maxima — system for symbolic and numerical computation.
                mpmath — a pure-Python library for multiprecision floating-point arithmetic.
                NumPy — numerical linear algebra and other numerical computing capabilities for Python.
                Pari/GP — a computer algebra system for fast computations in number theory.
                Pynac — a modified version of GiNaC that replaces the dependency on CLN by Python.
                R — a language and environment for statistical computing and graphics.
                And many more too numerous to list here.


                SAGE is not included with LaTeX, so you will either need to download a copy and install it to your computer locally OR, better yet, open a free Cocalc account and do your work in the cloud. In that case, you don't need SAGE on your computer but you will need access to the internet.







                share|improve this answer















                share|improve this answer




                share|improve this answer








                edited Oct 1 at 22:58

























                answered Oct 1 at 22:38









                DJPDJP

                8,6892 gold badges18 silver badges33 bronze badges




                8,6892 gold badges18 silver badges33 bronze badges































                    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%2f510418%2ftikz-declare-function-with-multiple-outputs%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

                    Tamil (spriik) Luke uk diar | Nawigatjuun

                    Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                    Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?