Ask Your Question

In sage plot: fill the area under a curve between two x-values.

asked 2011-11-27 05:50:42 -0600

anonymous user


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:


but I only want the area under the curve from x = 0.5 to x = 1.5 to be shaded in.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2011-11-27 06:19:28 -0600

DSM gravatar image

If 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

edit flag offensive delete link more


Good answer. At the same time, maybe we can support this option somehow without adding plots...

kcrisman gravatar imagekcrisman ( 2011-11-28 04:23:57 -0600 )edit

@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.

DSM gravatar imageDSM ( 2011-11-28 04:31:42 -0600 )edit

Great, file it and maybe we can get it at Sage Days 35.5!

kcrisman gravatar imagekcrisman ( 2011-11-28 06:45:27 -0600 )edit

Did the feature get implemented? If not, how could I give it a try?

Radu gravatar imageRadu ( 2013-05-16 01:25:13 -0600 )edit

Not that I know of. Since @DSM never got around to opening this (that I can tell), it's now [Trac 14599](

kcrisman gravatar imagekcrisman ( 2013-05-16 08:35:59 -0600 )edit

answered 2011-11-27 06:54:04 -0600

Sonya gravatar image

oh, okay, that makes sense, thank you!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-11-27 05:50:42 -0600

Seen: 1,781 times

Last updated: Nov 27 '11