Back to the Maple Tutorial Table of Contents
To plot multiple functions on a single graph, you will use the same plot() command and the same format. However, instead of including one function to be plotted, you will enclose the multiple functions in brackets and separate them with a comma.
Example: To plot the functions x, x2, and x3 on the same graph
> plot([x,x^2,x^3],x=-10..10,-10..10);
![[Maple Plot]](../images/plot-021.gif)
When you graph multiple functions, you can apply plot options to each function or just one function.
Example: To graph the functions x, x2, and x3 with a red line
> plot([x,x^2,x^3],x=-10..10,-10..10,color=red);
![[Maple Plot]](../images/plot-022.gif)
To make the line x2 blue we would use:
> plot([x,x^2,x^3],x=-10..10,-10..10,color=[red,blue,red]);
![[Maple Plot]](../images/plot-023.gif)
Notice how we specified a color for each function using a vector. A vector is a sequence enclosed in brackets. If you do not include an option for the last plot, the first option in the vector will be assumed.
Example:
> plot([x,x^2,x^3],x=-10..10,-10..10,color=[red,blue]);
![[Maple Plot]](../images/plot-024.gif)
You can use vectors with other plot options.
Example:
> plot([x,x^2,x^3],x=-10..10,-10..10,linestyle=[1,3,1],thickness=[2,1]);
![[Maple Plot]](../images/plot-025.gif)
You can save a plot in a variable. This will come in handy later when we need to display multiple plots or do animations.
The procedure is rather straightforward. To save the last plot in a variable:
> p:=plot([x,x^2,x^3],x=-10..10,-10..10,linestyle=[1,3,1],thickness=[2,1]):
When you save a plot into a variable, the variable contains a PLOT structure for the generated plot. The PLOT structure is what Maple actually uses to draw the plot.
Note the colon instead of the semicolon in the statement above. As you know, when you assign something to a variable, Maple reprints it. When Maple prints a PLOT structure, you see text values and commands used to create the plot. Since you really don't need to see that, use the colon to hide it. When you do complex plots, you can get pages of PLOT structures if you don't use the colon.
Once you have a PLOT structure in a variable, how do you get it out? You'll find out in the next section.
Before we can learn about display(), we must learn about packages. A Maple package is a group of functions, variables, and procedures that were created and grouped together.
There are two different ways to access a package. You can either use the long-hand notation to get to the function, or you can use the with() statement.
To use the long-hand notation, you would type package[function](arguments) instead of function(arguments)
To use the with() statement, you would use with(package). Then you would use the function just as if it weren't in a package.
Each method has different pros and cons.
Longhand form You can use one command instead of two If you use the same package over and over again, it can be repetitive with() Loads entire contents of package for the remainder of the session If two packages contain objects with the same name, they may conflict From now on, if I reference a member of a package, I will use the longhand form, but you can use either method to access it.
Back to our regularly scheduled tutorial...
To display a PLOT structure, you use the plottools[display]() command. The arguments of the command should be the PLOT structures.
For example:
> a:=plot(x,x=-10..10):
> b:=plot(x^2,x=-10..10):
> plots[display](a,b);
![[Maple Plot]](../images/plot-026.gif)
> with(plots): #Note that if you use the semicolon, you will receive all the members of the specified package.
> display(a,b);
![[Maple Plot]](../images/plot-027.gif)
You can include some plot options in your display statement. They will override plot options in the PLOT structure. As with the plot() statement, include them at the end, separated by commas.
> display(plot(x,x=-10..10),scaling=constrained); #Since the plot() statement returns a PLOT structure, you can display it without assigning it to a variable.
![[Maple Plot]](../images/plot-028.gif)