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;
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
add a comment
|
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
add a comment
|
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
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
tikz-pgf
edited Sep 30 at 17:04
Hyperplane
asked Sep 30 at 14:38
HyperplaneHyperplane
2751 silver badge8 bronze badges
2751 silver badge8 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
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
P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).
First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuffpgfmathsmuggle
to do the simplest things. I guess I should just do all plots inmatplotlib
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
@Hyperplanepgfmathsmuggle
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 usedmatplotlib
. 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
add a comment
|
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:
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.
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).
First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuffpgfmathsmuggle
to do the simplest things. I guess I should just do all plots inmatplotlib
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
@Hyperplanepgfmathsmuggle
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 usedmatplotlib
. 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
add a comment
|
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
P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).
First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuffpgfmathsmuggle
to do the simplest things. I guess I should just do all plots inmatplotlib
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
@Hyperplanepgfmathsmuggle
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 usedmatplotlib
. 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
add a comment
|
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
P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).
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
P.S. If you could consider posting complete MWEs I suspect other users would be much more willing to upvote your question(s).
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 stuffpgfmathsmuggle
to do the simplest things. I guess I should just do all plots inmatplotlib
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
@Hyperplanepgfmathsmuggle
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 usedmatplotlib
. 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
add a comment
|
First of all, thank you for this solution. It really makes me think though. Why does one have to do shady stuffpgfmathsmuggle
to do the simplest things. I guess I should just do all plots inmatplotlib
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
@Hyperplanepgfmathsmuggle
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 usedmatplotlib
. 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
add a comment
|
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:
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.
add a comment
|
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:
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.
add a comment
|
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:
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.
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:
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.
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
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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