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.Thu, 16 May 2013 15:35:59 +0200In sage plot: fill the area under a curve between two x-values.https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/How do I fill the area under a curve between two $x$-values using sage plot?
For example, maybe I am using the following code:
plot(x*(x-1)*(x-2)+1,0,2,fill=True)
but I only want the area under the curve from x = 0.5 to x = 1.5 to be shaded in.Sun, 27 Nov 2011 12:50:42 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/Answer by DSM for <p>How do I fill the area under a curve between two $x$-values using sage plot? </p>
<p>For example, maybe I am using the following code:</p>
<p>plot(x<em>(x-1)</em>(x-2)+1,0,2,fill=True)</p>
<p>but I only want the area under the curve from x = 0.5 to x = 1.5 to be shaded in.</p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?answer=12944#post-id-12944If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:
sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
![partly shaded picture](/upfiles/13224179424768595.png)
Sun, 27 Nov 2011 13:19:28 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?answer=12944#post-id-12944Comment by Radu for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=17684#post-id-17684Did the feature get implemented? If not, how could I give it a try?Thu, 16 May 2013 08:25:13 +0200https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=17684#post-id-17684Comment by kcrisman for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20808#post-id-20808Good answer. At the same time, maybe we can support this option somehow without adding plots...Mon, 28 Nov 2011 11:23:57 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20808#post-id-20808Comment by kcrisman for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=17682#post-id-17682Not that I know of. Since @DSM never got around to opening this (that I can tell), it's now [Trac 14599](http://trac.sagemath.org/sage_trac/ticket/14599).Thu, 16 May 2013 15:35:59 +0200https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=17682#post-id-17682Comment by kcrisman for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20806#post-id-20806Great, file it and maybe we can get it at Sage Days 35.5!Mon, 28 Nov 2011 13:45:27 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20806#post-id-20806Comment by Sonya for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=12945#post-id-12945oh, okay, that makes sense, thank you!Sun, 27 Nov 2011 13:54:04 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=12945#post-id-12945Comment by DSM for <p>If I'm understanding you correctly, then one way to do this is to take advantage of the fact you can add plots:</p>
<pre><code>sage: f = x*(x-1)*(x-2)+1
sage: p = plot(f, 0.5, 1.5, fill=True) + plot(f, 0, 2)
sage: show(p)
</code></pre>
<p><img alt="partly shaded picture" src="/upfiles/13224179424768595.png"/></p>
https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20807#post-id-20807@kcrisman: Sure, we'd simply need to have fillxmin and fillxmax and use those instead. Right now it looks like fill is using xmin and xmax for both purposes. (You could probably achieve the same effect by playing games with the function specifications but that seemed like more work than the above..) That would be a good beginner-level ticket for someone who already knows Python.Mon, 28 Nov 2011 11:31:42 +0100https://ask.sagemath.org/question/8513/in-sage-plot-fill-the-area-under-a-curve-between-two-x-values/?comment=20807#post-id-20807