ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 08 Aug 2012 08:40:03 +0200How to plot many functions on the same graphhttps://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/Hello, I have a list of functions but I don't know how to put them all on a single graph? I know one way to use 'show' like : show(plot1+plot2),
but is there a way that can cope with a function list or graph obj list? As maybe I'm not sure how many functions to plot.
for a specific exapmle:
var('x y')
f=x^0.5+y
lfs=[]
for i in range(5):
fs.append(f-i)
now how to show all functions in the lfs list on a single graph?Wed, 08 Aug 2012 05:10:57 +0200https://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/Answer by calc314 for <p>Hello, I have a list of functions but I don't know how to put them all on a single graph? I know one way to use 'show' like : show(plot1+plot2), </p>
<p>but is there a way that can cope with a function list or graph obj list? As maybe I'm not sure how many functions to plot.</p>
<p>for a specific exapmle:</p>
<pre><code>var('x y')
f=x^0.5+y
lfs=[]
for i in range(5):
fs.append(f-i)
</code></pre>
<p>now how to show all functions in the lfs list on a single graph?</p>
https://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/?answer=13904#post-id-13904That is it. You can also use the `sum` command to combine a list of plot objects.
f=x^2+10
p=[]
for i in range(0,5):
p.append(plot(f-i,(x,-3,3)))
sum(p)
You can use list comprehensions in Python to shorten this significantly and produce the same result.
sum([plot(x^2+10 - i,(x,-3,3)) for i in range(0,5)])
Wed, 08 Aug 2012 08:40:03 +0200https://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/?answer=13904#post-id-13904Answer by Aeol Kong for <p>Hello, I have a list of functions but I don't know how to put them all on a single graph? I know one way to use 'show' like : show(plot1+plot2), </p>
<p>but is there a way that can cope with a function list or graph obj list? As maybe I'm not sure how many functions to plot.</p>
<p>for a specific exapmle:</p>
<pre><code>var('x y')
f=x^0.5+y
lfs=[]
for i in range(5):
fs.append(f-i)
</code></pre>
<p>now how to show all functions in the lfs list on a single graph?</p>
https://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/?answer=13903#post-id-13903I've got a solution like this:
var('x')
g = Graphics()
g += plot(x-3, (x,-5,5))
g += plot(x-2, (x, -5, 5))
g.show()Wed, 08 Aug 2012 05:30:10 +0200https://ask.sagemath.org/question/9216/how-to-plot-many-functions-on-the-same-graph/?answer=13903#post-id-13903