Application Center - Maplesoft

App Preview:

Classroom Tips and Techniques: Context-Menu Plotting

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

 

Classroom Tips and Techniques: Context-Menu Plotting

Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow
Maplesoft
 

Introduction 

 

The Context Menu for a Maple mathematical expression in a single variable provides two distinct options for plotting.  In this month's article, we examine these options and provide a rationale for guiding the choice between them.  

 

Context-Menu Plotting Options 

 

The Plots option in the Context Menu for an expression such as sin(x) provides three relevant choices amongst the five shown in Figure 1.  These are 2-D Plot, 3-D Plot, and Plot Builder.  In a word, the first option invokes the smartplot command; the second, the smartplot3d command; the third, the plot command.  The 2-D Plot option and the Plot Builder provide a planar graph of the curve y = f(x).  The 3-D Plot option and the Plot Builder provide a graph of the developable cylinder z = f(x) with generator parallel to the y-axis. 

 

Image 

Figure 1   Options for plotting  sin(x) via Context Menu: Plots 

 

The functionality of the plot and smartplot commands differs slightly, and it is these differences we wish to explore. 

 

The smartplot Commands 

 

Figure 2 shows the application of the smartplot command to sin(x), the equivalent of selecting 2-D Plots in the Context Menu.  The resulting graph is drawn on the default range `and`(`<=`(-10, x), `<=`(x, 10)).  A range option for x cannot be be given.  The plot will always be drawn on this range. 

 

smartplot(sin(x)) 

Plot_2d
 

Figure 2   The smartplot command applied to sin(x)  

 

To obtain the graph on, say, `and`(`<=`(0, x), `<=`(x, `+`(`*`(2, `*`(Pi))))), use the Context Menu for the graph, selecting Axes/Properties as per Figure 3. 

 

Image 

Figure 3   Axis Properties from the Context Menu of the graph in Figure 2 

 

Uncheck the box to the left of "Use data extents" and type new endpoints into the boxes labeled "Range min" and "Range max".  Note that `+`(`*`(2, `*`(Pi))) must be entered as 6.28 because (at the present time) the Context-Menu modifications can contain neither arithmetic calculations nor symbolic constants.  Clicking the OK button will change Figure 2 to Figure 4. 

 

Plot_2d 

Figure 4   The Context-Menu modified version of Figure 2. 

 

The inability to obtain a graph on precisely the interval `and`(`<=`(0, x), `<=`(x, `+`(`*`(2, `*`(Pi))))), would seem to be a grave defect in the use of the smartplot.  However, there is a significant redeeming feature of this command. 

 

If the Context Menu option Axes/Properties is used to increase the range of the graph in Figure 4, say to `and`(`<=`(0, x), `<=`(x, 15)), the smartplot retains knowledge of the function sin(x) and the additional data points needed to draw the graph on the extended range can be recomputed.  I call this the "re-scalable axis" property, and it is illustrated in Figure 5 where the Context Menu for Figure 4 was used to rescale the horizontal axis beyond even the original default bound. 

 

Plot_2d 

Figure 5   Horizontal axis in Figure 4 rescaled by Context Menu 

 

Another strength of the smartplot command is its ability to graph implicitly.  Figure 6 shows the result of applying this command to the equation of the unit circle.  Again, application of this command is equivalent to selecting 2-D Plot from the Context Menu. 

 

smartplot(`+`(`*`(`^`(x, 2)), `*`(`^`(y, 2))) = 1) 

Plot_2d
 

Figure 6   An implicitly drawn graph via the smartplot command. 

 

A final feature of a graph generated by the smartplot command is the retention of the plot window under the drag-and-drop plotting option.  Thus, to add the graph of an additional function to an existing graph, drag-and-drop (or copy/paste) the expression for the rule of the function onto the graph.  Figure 7 shows the result of dropping x onto the graph in Figure 4; Figure 8, the result of dropping x onto the graph in Figure 6; and Figure 9, the result of dropping x onto a modified Figure 6. 

 

Plot_2d 

Plot_2d 

Plot_2d 

Figure 7   Drop x onto Figure 4 

Figure 8   Drop x onto Figure 6 

Figure 9   Drop x onto modified Figure 6 

 

The modification of Figure 6 that results in Figure 9 is the "freezing" of the plot window in Figure 6.  The Axes/Properties dialog must be invoked via the Context Menu, and as per Figure 3, the existing endpoints (both horizontal and vertical) of -1 and 1, must be "locked in" by clicking the Apply button for both directions. 

 

It is also possible to modify Figure 8 to look like Figure 9.  Just use the Axes/Properties dialog from the Context Menu for Figure 8.  Starting from Figure 6, the net amount of "work" needed to create Figure 9 is the same in either event.  And clearly, the passage of Figure 4 to Figure 7 retained the plot window of Figure 4 because that window had been set by the adjustment to the default window that generated Figure 4. 

 

The cylinder z = sqrt(`+`(1, `-`(`*`(`^`(x, 2))))), `<=`(0, x), `<=`(y, 1), in Figure 10 can be drawn with the Context Menu by selecting Plots/3-D Plots/x,?, which implements the smartplot3d command.  In general, z = f(x, y) with either of x or y missing, defines a generalized cylinder, that is, a developable surface with generator parallel to the coordinate axis of the missing variable. 

 

Initially, the graph is the one in Figure 11, but the Context Menu options for this graph can be used to transform the image to the one seen in Figure 10. 

 

Plot 

Plot 

Figure 10   The smartplot3d command draws the cylinder z = sqrt(`+`(1, `-`(`*`(`^`(x, 2))))), `<=`(0, x), `<=`(y, 1) 

Figure 11   The initial graph of the cylinder z = sqrt(`+`(1, `-`(`*`(`^`(x, 2))))), `<=`(0, x), `<=`(y, 1), provided by the smartplot3d command 

 

The Plot Builder 

 

When sin(x), `and`(`<=`(0, x), `<=`(x, `+`(`*`(2, `*`(Pi))))), is graphed by the Plot Builder launched from the Context Menu, it is possible to set the plotting range before generating the plot.  Moreover, endpoints such as 2*Pi or sqrt(2) are admissible.  Figure 12 shows the Plot Builder settings that produce the desired graph. 

 

Image 

Figure 12   Context-Menu launched Plot Builder for sin(x)  

 

The Preview button on the lower right provides a preview of the graph.  When the preview pane is closed, control is returned to the Plot Builder so additional modifications can be made.  Thus, before the graph is embedded in the worksheet, the plot and the plot window can be adjusted until they are optimal. 

 

The graph of sin(x) produced by the Plot Builder is generated with the plot command.  At the present time, such plots do not retain the rule of the function in the plot data structure.  Hence, interactive rescaling changes an axis, but does not recompute any new points from which a new graph is to be drawn.  For example, if `*`(`^`(x, 2)) is graphed on `and`(`<=`(0, x), `<=`(x, 1)), and then the Context Menu for this graph used to change the plot window to `and`(`<=`(-1, x), `<=`(x, 1)), the result will be the graph shown in Figure 13. 

 

Plot_2d 

Figure 13   Interactively enlarging plot window in a graph generated by plot command 

 

In essence, this observation suggests that when using the Plot Builder, it's best to use the Preview option to set the plot window appropriately before embedding the graph.  Enlarging the plot window via the graph's Context Menu does not work, but shrinking it (where no new points need to be computed) certainly does work. 

 

A graph drawn by the plot command will retain its plot window under drag-and-drop plotting.  Figure 14 shows the result of dropping x onto the graph of sin(x), `and`(`<=`(`+`(`-`(Pi)), x), `<=`(x, Pi)), that was drawn by the Plot Builder (which itself uses the plot command). 

 

Plot_2d 

Figure 14   Drag-and-drop x onto graph of sin(x), `and`(`<=`(`+`(`-`(Pi)), x), `<=`(x, Pi)), drawn by plot command 

 

The plot window does not revert to the default interval [-10, 10].  Unfortunately, this is not the case for the implicit plot, based on the implicitplot command, drawn by the Plot Builder.  Figure 15 shows the Plot Builder's Preview for `+`(`*`(`^`(x, 2)), `*`(`^`(y, 2))) = 1, the unit circle.  The default plot window is `<=`(-5, x), `<=`(y, 5), and the test points used by the implicitplot command are uniformly distributed over this region.  Hence, too few fall on (or near) the circle.  Figure 16 shows the graph that results when the plot window is changed (in the Plot Builder) to `<=`(-1, x), `<=`(y, 1).  Finally, Figure 17 gives the result of dropping x onto Figure 16. 

 

Plot_2d 

Plot_2d 

Plot_2d 

Figure 15   Implicit plot of unit circle drawn by Plot Builder using default plot window `<=`(-5, x), `<=`(y, 5) 

Figure 16   Implicit plot of unit circle drawn by Plot Builder with plot window `<=`(-1, x), `<=`(y, 1) 

Figure 17   Graph resulting from dropping x onto Figure 14 

 

The plot window for the implicitly drawn graph reverts to the default window of the function added to the graph.  In this case, the default is that of the plot command, namely, the interval [-10, 10]. 

 

Figure 10 can be drawn with the Plot Builder if the Edit Functions button is clicked.  Figure 18 shows the pane that opens, and in which y is added as a second variable in the Add Variables region. 

 

Image 

Figure 18   Adding y to the list of variables in order to draw the cylinder z = sqrt(`+`(1, `-`(`*`(`^`(x, 2))))), `<=`(0, x), `<=`(y, 1), with the Plot Builder 

 

Summary 

 

Table 1 summarizes our findings for the plot (and implicitplot) commands behind the Plot Builder option in the Context Menu/Plots choices, and for the smartplot behind the 2-D Plot option (or smartplot3d behind the 3-D Plot option). 

 

Property 

 

Re-scalable axis 

Window safe under drag-and-drop 

Algebraic or symbolic endpoints 

Cylinder 

Plot Builder 

plot 

implicitplot 

no 

no 

yes 

no 

yes 

yes 

yes 

N/A 

smartplot 

explicit 

implicit 

yes 

yes      

yes 

yes (*) 

no 

no      

yes 

N/A    

Table 1   Comparison of Plot Builder and smartplot options in the Context Menu selection Plots. (*) - the functionality is available only if the plot window has been "frozen". 

 

The smartplot and smartplot3d commands: 

(+) expanding the horizontal axis "grows" the graph of the function 

(+) if first "frozen," plot window is preserved under drag-and-drop plotting 

(-) algebraic and symbolic endpoints not allowed 

(-) Axes/Properties dialog not user-friendly 

(-) Context Menu modifications must be applied one-by-one, each requiring a re-launch of the Context Menu 

 

The Plot Builder: 

(+) plot window for explicit plot preserved under drag-and-drop plotting 

(+) algebraic and symbolic endpoints are allowed 

(+) Preview button and range-change dialog very user-friendly 

(+) all plot options available in one pane via the Options button 

(-) plot window for implicit plot not preserved under drag-and-drop plotting 

(-) expanding the horizontal axis does not "grow" the graph of the function after leaving the Plot Builder 

 

Consequently, it was, and still is, this author's opinion that the Plot Builder is the tool-of-choice for interactive graphing. 

 

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.