ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 27 Oct 2010 16:16:25 -0500Plotting Overlapping Curveshttp://ask.sagemath.org/question/7744/plotting-overlapping-curves/Stupid newbie question!
I want to be able to plot two or more functions on a single graph. For example, I wish to plot $x^2$ and $2^x$, say in red and blue, such that a person can readily see, with their eyes, where the two curves intersect.
Unfortunately, I can't figure out how to make this happen. It seems like it would be a common teaching device but how to make it work?
Any assistance welcomed!Tue, 26 Oct 2010 11:40:14 -0500http://ask.sagemath.org/question/7744/plotting-overlapping-curves/Answer by kcrisman for <p>Stupid newbie question!</p>
<p>I want to be able to plot two or more functions on a single graph. For example, I wish to plot $x^2$ and $2^x$, say in red and blue, such that a person can readily see, with their eyes, where the two curves intersect.</p>
<p>Unfortunately, I can't figure out how to make this happen. It seems like it would be a common teaching device but how to make it work?</p>
<p>Any assistance welcomed!</p>
http://ask.sagemath.org/question/7744/plotting-overlapping-curves/?answer=11760#post-id-11760You shouldn't even need the `axes=True` part, I think. If you look at
sage: plot?
you'll see that `+` is the standard way to add plots.
It sounds like you might want to plot things in a certain order of objects on top of each other; here, the `zorder` option should often work (though there might be some graphics primitives where it doesn't). Like so:
sage: P = plot(sin,0,pi,zorder=50)
sage: Q = plot(cos,0,pi,color='red',zorder=51)
sage: P+Q
Here, red is on top (like in a plot with no zorder)
sage: Q = plot(cos,0,pi,color='red',zorder=40)
sage: P+Q
Here, blue is on top.
Note that the behavior without zorder set is sometimes a little enigmatic - I don't know whether `P+Q` and `Q+P` always plot the second one on top if you don't use `zorder` above, since for certain objects that doesn't seem to happen; for these plot types, apparently that does happen, though.Wed, 27 Oct 2010 16:16:25 -0500http://ask.sagemath.org/question/7744/plotting-overlapping-curves/?answer=11760#post-id-11760Answer by gt4431b for <p>Stupid newbie question!</p>
<p>I want to be able to plot two or more functions on a single graph. For example, I wish to plot $x^2$ and $2^x$, say in red and blue, such that a person can readily see, with their eyes, where the two curves intersect.</p>
<p>Unfortunately, I can't figure out how to make this happen. It seems like it would be a common teaching device but how to make it work?</p>
<p>Any assistance welcomed!</p>
http://ask.sagemath.org/question/7744/plotting-overlapping-curves/?answer=11759#post-id-11759Okay, answering my own question, in case someone else got confused like I did:
<pre>
p1 = plot(x^2,(x,0,5),rgbcolor=hue(0.4))
p2 = plot(2^x,(x,0,5),rgbcolor=hue(0.6))
show(p1+p2, axes=true)
</pre>
Here the function of the '+' operator seems to mean "and" rather than "plus".Tue, 26 Oct 2010 11:48:23 -0500http://ask.sagemath.org/question/7744/plotting-overlapping-curves/?answer=11759#post-id-11759