Overlaying plots

As you know, you can easily plot a set of functions, e.g.:

> plot( {x^2 + 3*x + 7, 100 - 6*x, x^3 - 40*x + 40 }, x = -5..5 );

[Maple Plot]

Sometimes you want to show two plots that (perhaps) use different styles. That requires a different approach. For example, you can separately plot two curves:

> plot( {x^2 + 3*x + 7, 100 - 6*x }, x = -5 .. 5 );

[Maple Plot]

and a list of four points:

> plot( [ [-4, 40], [-1, 70], [2, 100], [3, 50] ],
style = point, symbol = circle, color = blue );

[Maple Plot]

but how do you get the points and the curves on the same picture? The answer (which you saw in an earlier Math with Maple workshop but may have forgotten) is to store the two plots in variables and then use the display command to display them together:

> with(plots):
plot1 := plot( {x^2 + 3*x + 7, 100 - 6*x }, x = -5 .. 5 ):
plot2 := plot( [ [-4, 40], [-1, 70], [2, 100], [3, 50] ],
style = point, symbol = circle, color = blue ):
display( {plot1, plot2} );

[Maple Plot]

>

To use display , you need to load the plots library, which is what with(plots): does. I put colons (instead of semicolons) at the end of the first three lines because their output is uninteresting. (You can try changing them to semicolons if you want to see the uninteresting output for yourself.) All I really care about is the result of the display command, which overlays the two plots.

This same idea is useful if you want to display two curves over two different ranges, or if (as we will see later in the term) you want to animate the curves!