Part 4: Plotting - Maple Programming Help

Home : Support : Online Help : Getting Started : Tutorials : MaplePortal/Tutorial4

Part 4: Plotting

 Introduction Maple Tutorials are designed to help you get started with Maple, learn about the key tools available in Maple, and lead you through a series of problems.   In Part 4: Plotting, you will create 2-D and 3-D plots.  You will learn how to combine multiple plots and create animations.  You can create plots from a context menu, a command, or the Plot Builder Assistant.   To try this material on your own, start with an empty Maple document. Perform the steps described in the left column of each table below.  The results of the steps are displayed in the right column for reference.   Refer to Help > Quick Reference for basic getting started tips.   Note for non-Windows users: The keystrokes given in this document are for Windows.  There will be differences for other platforms. If you are using a different platform, see Help > Quick Help for the list of the most common keystrokes.

2-D and  3-D Plots

Maple can produce 2-D and 3-D plots of equations and expressions.

Steps

Result

2-D Plots

Learn to plot in Maple.  The fastest way to plot an expression in Maple is to use the context menu.

Example: Enter an expression in x (such as ), right-click on the expression, and select Plots > 2-D Plot.

Example: Use the point probe to find the coordinates of different points in the graph. Right-click on the plot, then select Probe Info>Nearest point on line. When you hover over a point on the graph, the coordinates are displayed.

Example: To pan the plot, right-click on the plot, and select Manipulator>Pan. Hold down the left mouse button and use the mouse to move the plot around. To scale the plot, perform the same steps, but select Manipulator>Scale.

Tip: You can also change the manipulator tool by clicking on the plot, and then selecting the appropriate tool from the plot toolbar:

Example: Enter an expression in x (such as ${\mathrm{sin}}^{2}\left(x\right)$), right-click on the expression, and select Plots > 2-D Plot.

Observe that the default x-range for plots is -10 to 10 for most plots, but it is $-2\mathrm{π}$ to $2\mathrm{π}$ for trigonometric plots.



$\to$ 

${\mathrm{sin}}^{2}\left(x\right)$$\to$ 



Setting the Axis Properties for a Plot

The default $y$-range for a plot is chosen based on the values computed.  You can set the range after creating a plot by modifying the axis properties.

Example:  Click on the plot, then select the Axis Properties button  from the plotting toolbar.  For both the horizontal and vertical axes, you can set min and max values, set number of tickmarks, and control advanced features such as number of subticks.

Example: Modify the vertical range for the plot of  :  Click on the plot, then select the Axis Properties button  from the plotting toolbar.  Under the Vertical tab, clear the Use data extants check box, and change the Range min to -15.



$\to$ 



Combining Plots

You can easily add another plot on the same set of axes.

Example: Enter another equation in $x$ (such as $\mathrm{sin}\left(\frac{x}{2}\right)$), highlight the new expression with your mouse, and drag it onto the plot.

Tip: When you select and drag the expression onto the plot, the expression is deleted from its original position.  Another way to drag is to use the Copy and Drag feature:

 • Highlight the expression, hold [Ctrl], and drag it onto the plot.

For this and other tips, see the Quick Reference Card (Help>Quick Reference).



${\mathrm{sin}}^{2}\left(x\right)$$\to$ 



$\mathrm{sin}\left(\frac{x}{2}\right)$

Annotating Plots

You can add titles, captions, and legends to plots.  (From the context menu, select Title or Legend.)

You can also add additional information to plots by using the drawing tools.  Lines, arrows, text, 2-D math, and shapes are available.

Example: Click on the plot, then click on the  button on the toolbar. Use the text tool (T) to enter labels for the curves.  Use [F5] to toggle between text and math, and enter labels for the curves in Math mode.





Plotting with Commands

Example:  Graph a polynomial using the plot command.

Note that when you do not specify a range, the default $x$-range [-10, 10] is used.

Example:  Graph the polynomial again, this time specifying the range [-3, 5].  A range in Maple is given by a..b.

For more information and examples using the plot command, see plot.



$\mathrm{plot}\left({x}^{3}-4{x}^{2}-x+4\right)$

$\mathrm{plot}\left({x}^{3}-4{x}^{2}-x+4,x=-3..5\right)$



To display multiple plot structures into a single graph using commands, use plots[display].

Example:  Enter two plot commands.

Then use plots[display] to see both curves in a single graph.

$\mathrm{plot1}≔\mathrm{plot}\left(\mathrm{ln}\left(x\right),x=0..25\right):$

$\mathrm{plot2}≔\mathrm{plot}\left(\mathrm{ln}\left(x-5\right),x=0..25\right):$

$\mathrm{plots}\left[\mathrm{display}\right]\left(\left[\mathrm{plot1},\mathrm{plot2}\right]\right)$



Steps

Result

3-D Plots

You can create 3-D plots.

Example: Enter an expression in x and y (for instance, $\mathrm{sin}\left(x\right)\cdot y$ ).  Right-click on the expression and use Plots > 3-D Plots > x,y from the context menu.

Example: Rotate the plot by clicking on the plot, holding down the left mouse button and moving the mouse.

Example: Pan and scale the plot by selecting a different tool from the Manipulator list on the context menu.  Now when you hold down the mouse button and move the mouse, the new action is performed.

Tip: You can also change the manipulator tool by clicking on the plot, and then selecting the appropriate tool from the plotting toolbar:

Note that the default x-range and y-range for plots is -10 to 10 for most plots, but it is $-2\mathrm{π}$ to $2\mathrm{π}$ for trigonometric plots.





$\mathrm{sin}\left(x\right)\cdot y$$\to$ 

Plot Options

You can modify the look of your plot in a variety of ways.

Plot options can be changed by right-clicking on the plot and modifying the options within the context menu.  Note that the choices available in the context menu are specific to 3-D plots.

Example: Right-click on the plot to obtain the context menu.  Click Color and choose XY to modify the shading.

Example: Click on the plot, and then from the context menu select Axes>Boxed.

Plot options can also be changed by clicking on the plot, selecting the Plot menu, and selecting the relevant options.





$\mathrm{sin}\left(x\right)\cdot y$$\to$ 

Plotting in 3-D with Commands

Example:  Graph a polynomial using the plot3d command.

For more information on the plot3d command, see plot3d.

Note that when you do not specify a range, the default x-range and y-range for plots is -10 to 10 for most plots, but it is $-2\mathrm{π}$ to $2\mathrm{π}$ for trigonometric plots.





Plotting Guide

In addition to plot and plot3d, many other plotting commands are available. The PlottingGuide makes it easy to find the plot type you need. You can also access the plotting guide from Help > Maple Help > Table of Contents > Graphics > Plotting Guide.

Using the Plot Builder Assistant

Steps

Result

Plots can easily be created in Maple using the built-in Plot Builder.

Example: Enter the expression you want to plot.  From the context menu, select Plots>Plot Builder.  Using the Plot Builder, you can choose the kind of plot you want, add titles, and set options, all at once. This example shows the use of plot title, normal axes and the style surface with contour.

The Plot Builder allows you to create more than just ordinary 2-D and 3-D plots.  The example on the right is a contour plot.

Example: Enter the expression ${x}^{2}+{y}^{2}$.  Select Plots>Plot Builder from the context menu.  Select 2-D Contour Plot from the Select Plot list box, then click Plot.

${x}^{2}+{y}^{2}$$\to$ 



${x}^{2}+{y}^{2}$$\to$   

You can also create an animation using the Plot Builder assistant.

Example:  Enter the expression on the right, right-click to invoke the context menu.

Select Plots>Plot Builder.  Select Animation from the Select Plot Type drop-down list and click the Plot button.

Now click on the plot image.  The animation toolbar is now available.  Click the Play button  and watch the animation.  To step through the frames of the animation, click .

$\frac{\mathrm{sin}\left(a\cdot \sqrt{{x}^{2}+{y}^{2}}\right)}{{\mathrm{\pi }}^{2}}$$\to$     

Using the Plot Builder to Return a Plot Command

Exercise:  Find the derivative of and plot the result.

 1 To enter the expression: Use symbol completion to create the exponential In Math mode, type e. press Esc, and select e (exponential) from the list.
 2 To compute the derivative:  From the context menu, choose Differentiate.
 3 To apply the Plot Builder: Select the output (the derivative) and choose the Plot Builder.  Modify the view so the $t$ range is 0..10 and the $y$ range is -2000..2000.  Preview the result.  When you are done, click Command to return the plot command.

Tip:  If you use the Plot Builder to create a plot and then return the plot command, you can easily modify and reuse this command.  To use the command, simply copy the command to a new line and execute.



$\frac{{ⅇ}^{t}}{t}$$\stackrel{\text{differentiate w.r.t. t}}{\to }$$\frac{{{ⅇ}}^{{t}}}{{t}}{-}\frac{{{ⅇ}}^{{t}}}{{{t}}^{{2}}}$$\to$${\mathrm{plot}}{}\left(\frac{{{ⅇ}}^{{t}}}{{t}}{-}\frac{{{ⅇ}}^{{t}}}{{{t}}^{{2}}}{,}{t}{=}{0}{..}{10}{,}{\mathrm{view}}{=}\left[{\mathrm{DEFAULT}}{,}{-}{2000}{..}{2000}\right]{,}{\mathrm{labels}}{=}\left[{t}{,}{y}\right]\right)$





Exercise: Use the Plot Builder to create an interactive plot with 3 parameters for the expression $\mathrm{sin}\left(a\cdot x+b\right)+c$.