Constructing Advanced Plots
? Maplesoft, a division of Waterloo Maple Inc., 2006
Introduction
Maple offers many different tools for creating plots. The context-sensitive menu allows you to create a plot with just a few clicks. The Plot Builder (Demonstrated in an earlier tips and techniques) allows you to specify different options for your plots. Maple's plotting packages allow you to create complex plots made up by many parts. This Tips and Techniques will demonstrate commands from Maple's plotting packages.
Demonstrated below are ways to combine different plots; describe your plots with legends; customize your plots; add different shapes and text to your plots; and create animated plots.
Combining multiple plots
When working with Maple's plotting commands, you will often want to have multiple plots appear together. You can accomplish this when plotting expressions by dragging one or more expressions onto a plot. When you wish to have the plot generated using Maple input or wish to use shapes such as those explained later, you can use plots[display] . This command will take all the plots given in a list and display them together in a single plot.
To demonstrate, we'll plot, sin(x) and cos(x) together. First, assign each plot to a variable. Use a colon at the end of each line to suppress the output of the plot structure.
Now use plots[display] to output both plots into one plot. Just pass a list of plots in, and plots[display] will combine all of the given plots
And there we have it, two plots combined together. Adding more plots it as easy as adding another element to the list given to the command.
Adding a legend
In our first plot we can clearly see both the sine and cosine curves. However it would be easier to figure out which one is which if there was a legend on the plot. Any options that you specify in the original plot commands will get passed on to the display command. So let's modify the original plots and add a legend and color to the plots.
More Options
You can also give plot options to the display command which will then be applied to all of the plots in the list. See ?plot,options for information on all of the options that can be used.
Let's increase the thickness of the lines used. We will also add a title to the plot.
You will see that by adding the thickness option to plots[display], both lines had their thickness increased. If you want the lines to have different thickness you can define the thickness when the lines are created:
Adding shapes to your plots
The plottools package offers many different shapes that you can use within your plots. The shapes it generates can be either two or three dimensional. Several functions s can create both 2-D and 3-D plots. With these functions, if you give the function a position with two coordinates, you will get a 2-D plot and if you give three coordinates, you will get a 3-D plot.
To demonstrate, we will create several lines by giving the start and end points.
Now, we can do the same thing in 3-D
As you can see the only difference is the extra dimension given for each coordinate.
Now let's demonstrate some of the other shapes that you can create.
You can create a sphere , giving the center of the sphere and its radius.
A disk , again with the center and the radius
A cylinder with the center, radius, and height
Or even a dodecahedron with the center and scale
Including text
plots[textplot] makes it easy to place text anywhere you would like on your plot. You can give textplot a list of lists describing the text that you would like to appear. The parameters are: the coordinates for the text and the actual text. As an example, we will label an intersection of the sine and cosine curves from our first example.
Find the intersection point
And create the text. We'll offset the x value a bit so that the text does not interfere with the plot. We also use the align option to specify that we want the text aligned to the right hand side of the given point.
Now use textplot3d to see that we can place the text anywhere we would like in 3-D. Below we will label several points on a sphere.
Try rotating the above plot by clicking and dragging the mouse, you'll see that the text is in 3-D.
Using Arrows
Often you may wish to display an arrow that can be used to point out a specific part of a plot. This can be done with plots[arrow] . Arrows can be in two or three dimensions. The arrow can take one or two arguments. If one argument is given, it will create an arrow from the origin with the first argument taken as a direction vector. If two arguments are given, the first is the start point, the second is the direction vector.
First, we will create a 2-D example with an arrow pointing to the maximum of the sine curve.
To change the plot to 3-D, just add a third dimension to each coordinate. For an example of 3-D arrows, see the demonstration in the last section of this document.
Animating your plots
It is simple to create animations in Maple using the plots[animate] command.
The animate command takes at least three parameters. The first is the name of the plot function you wish to use. The second is a list of parameters that you would have given the plot function. The last is a variable and range you want the animation to travel between.
As an example, lets show a simple 3-D plot. To create the animation, we will first create the plot we wish to animate.
Now we create the animated version. The first argument of the animate command is the plot command used to create each frame. The second argument is a list containing the arguments to that plot command.
To see the animation, click on the plot, and then click on the play button that appears on your toolbar.
Demonstration: Cross product
As a demonstration of putting together a number of plot tools, we will recreate this image taken from the Wikimedia Commons
First, we will create the arrows. There are five arrows all of which start at the origin, so we can use the one parameter version of plots[arrow]
You can see that we did use the two parameter version for the blue arrows. This is is because if we were to start both the blue and red arrows at the origin, you would only be able to see the blue arrow. Since it is longer, it would cover up the red arrow.
Now let's add the lines. We define some values that will be the same for all of the lines first.
And then the actual lines
Next, add the arc. plottools[arc] , takes three parameters, the center of the circle, the radius of the circle, and a range between the starting angle of the arc (in radians) and the ending angle of the arc.
Ok, we have a problem. plottools[arc] only generates 2-D plots. What we need to do is convert the 2-D plot of an arc into a 3-D plot. First, let's look at the 2-D plot.
Now we will use plottools[transform] to convert the 2-D plot into a 3-D plot. transform takes one parameter, f, which is a procedure that maps two coordinates into three coordinates. The function returns a procedure that we can call to convert a plot structure. For our example,we'll map x to the x coordinate in 3-D. Set the y to the 3-D z coordinate and set the 3-D y coordinate to zero.
Do the transformation
And display it.
As you can see, we got a 3-D plot. So now we can add it to our plot
Finally, we'll create the text that describes the plot.
There we have it - our plot. And unlike the original, this plot can be easily modified, added to, and because it is a 3-D object, it can be rotated. This document demonstrates the combination of several of Maple's plotting tools to create an interactive and attractive plot. We leave it as an exercise to the reader to change the colors of the letters to match up with the colors of the arrows.
Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.