MaplePortal/PlottingTips - Help

Home : Support : Online Help : MaplePortal/PlottingTips

 > $\mathrm{plots}[\mathrm{interactive}]();$

Plotting Tips: Vertical Lines and Axis Labels

Introduction

Certain graphing techniques are essential in the classroom but are not covered by basic plotting examples in Maple.  Here, you will learn three interactive plotting strategies:

 • plot vertical lines
 • control axis labels (for instance, labels with multiples of $\mathrm{π}$)
 • create a graph interactively and then efficiently reuse that graph

These are not complicated techniques, and once you have discovered them you will be able to employ them to make better graphs for classroom presentations and handouts as well as save yourself time and effort.

Commands, context-menus, and the Plot Builder are discussed.  The Plot Builder is Maple's most robust interactive plotting tool.  It provides access to a variety of plot types and to the plot options that enable you to customize your graph.  As you change the options in the Plot Builder, preview your graph.  Once you are satisfied, return a plotting command that can be reused and modified.  With the Plot Builder, your trigonometric plots can be easier to read and convey more useful information.

Initializations

 > $\mathrm{restart}$
 > $\mathrm{with}\left(\mathrm{plots}\right):$

Plotting the Graph of a Vertical Line

In the $\mathrm{xy}$-plane, the graph of the solution set of the equation $x=1$ is a vertical line.  This line cannot be obtained as the graph of a function, so Maple's plot command will not graph the vertical line without user intervention.  Figure 1 shows a portion of this line drawn with the plot command as a line segment.  Figure 2 draws this same line segment as the parametric curve $x\left(t\right)=1,y\left(t\right)=t$.

 > $\mathrm{plot}\left(\left[\left[1,-1\right],\left[1,1\right]\right]\right)$

 > $\mathrm{plot}\left(\left[1,t,t=-1..1\right]\right)$

Figure 1   Graph of the vertical line segment by specifying its endpoints

Figure 2   Parametric plot of the vertical line segment


Clearly, graphing a vertical line segment via the plot command requires significant user intervention and knowledge of Maple syntax.  Figure 3 provides a graph of the vertical line segment drawn as an implicit plot with the implicitplot command from the plots package.

 > $\mathrm{implicitplot}\left(x=1,x=0..2,y=-1..1\right)$

Figure 3   Graph of the vertical line $x=1$ drawn as an implicit plot



For more information on these methods, see plot details and parametric plot

Figures 1 - 3 all require some mathematical insight on the part of the user, who must correspondingly implement some appropriate Maple construct that reflects that view of the vertical line.  Now what happens when the user naively tries to plot $x=1$ interactively via the context menu?  Right-click the equation $x=1$ and from the context menu, select Plots>2-D Implicit Plot>$\mathbit{x}\mathbf{,}\mathbf{\text{?}}$.

 $x=1$$\to$ Figure 4   Context menu plot of the vertical line $x=1$



The result is shown in Figure 4. You can obtain the graph through the context menu as well as by using a command.  A final way to graph a vertical line is using the Plot Builder.

First, launch the Plot Builder from the Tools>Assistants menu. In the Expressions section, click the Add button, and enter $x=1$.

Pressing the Accept button will enter the equation $x=1$ into the Expression box and add the variable $x$ to the Variables box.  In the Variables section, click the Add button and add the variable $y$.  Press Accept.  Figure 5 shows the completed Specify Expressions dialog.

 Figure 5   Specify the expressions and variables

Press OK and then press Plot in the main Plot Builder window.  Again, you get the graph of the vertical line.

 Figure 6   The Plot Builder now draws the plot as a 2-D implicit plot

Controlling the Labeling of an Axis

Using the Context Menu

Consider the graph of $\mathrm{sin}\left(x\right)$.  On the horizontal axis, the default range ( for a trigonometric graph), default tickmarks (at multiples of $\mathrm{π}$), and default labels are shown.

 > $\mathrm{plot}\left(\mathrm{sin}\left(x\right)\right)$

 > 

Figure 7   The default plot of $\mathrm{sin}\left(x\right)$

If you want to to change the tickmarks and labels on x-axis to whole number multiples of $\mathrm{π}$, you can do so after the graph has been drawn.

Click on the graph to select it, then from the Plot menu choose Axes>Properties.... (You can also access this from the context menu for the plot.)  The Axis Properties box is shown in Figure 8.

Under the Horizontal Axis tab, clear the box for Let renderer choose tickmarks, and instead select Custom Spacing (1.0) and Multiply by Pi.  The modified graph is shown in Figure 9.

 > $\mathrm{plot}\left(\mathrm{sin}\left(x\right)\right)$

 > 

Figure 8   The Axis Properties

Figure 9 Modified graph with $\mathrm{π}$ in the labels

Using the Plot Builder

When graphing with the Plot Builder, you can also access these options.  Use the context menu to launch the Plot Builder for your expression, such as  $\mathrm{sin}\left(x\right)$.

In the Plot Builder, press the Options button to access the dialog for plot options, then select the Advanced Settings option under Axes on the lower left.  In the Advanced Axis Settings dialog box, open the drop-down listing under Tickmarks for the $x$-axis.  Select spacing(Pi, 0).

 > $\mathrm{plots}[\mathrm{interactive}]();$
 > $\mathrm{plots}[\mathrm{interactive}]();$

 Figure 10   On the left, click Advanced Settings in the Axes box; on the right, in the $x$-row of the Axis box, click the down arrow in the Tickmarks column and select spacing(2, 0), the last item in the drop-down list.

Press the Apply button and then Plot.

Graphing Efficiently: Return a Command You Can Reuse

In the previous example, a plot was created through the Plot Builder.  If you are creating many plots, this can become a tedious way to create the modifications you want.  For more efficient graphing, you can use the Plot Builder once, and extract command with all the settings you selected.

When exiting the Plot Builder, instead of returning a plot, you can opt to return the command used to create the plot.  This provides a way to learn the way to specify these options directly to the plot command.  If you intend to graph numerous similar functions with the same plot settings, this is an efficient way to do it.

Here are the steps to create the same plot as in the previous section and then to return a command from Plot Builder:

Use the context menu to launch the Plot Builder for your expression, such as $\mathrm{sin}\left(x\right)$.

In the Plot Builder, press the Options button to access the dialog for plot options, then select the Advanced Settings option under Axes on the lower left.  In the Advanced Axis Settings dialog box, open the drop-down listing under Tickmarks for the $x$-axis.  Select spacing(Pi, 0).

Press Apply and then Command.

The result obtained from choosing Command instead of Plot is shown in Figure 11.

 $\mathrm{sin}\left(x\right)$$\to$${\mathrm{plot}}{}\left({\mathrm{sin}}{}\left({x}\right){,}{x}{=}{-}{2}{}{\mathrm{π}}{..}{2}{}{\mathrm{π}}{,}{\mathrm{tickmarks}}{=}\left[{\mathrm{spacing}}{}\left({\mathrm{π}}{,}{0}\right){,}{\mathrm{default}}\right]\right)$ Figure 11   The command returned from Plot Builder

Now, you can copy and paste this command on a new line (ensure you are in 2-D math mode when you paste it)  to create a graph.   You can modify the command to create variations.  For instance, you can graph $\mathrm{cos}\left(x\right)$ without having to go through the Plot Builder steps again.

Some final illustrations of graphs obtained by modifying this command.

1. Graph of $\mathrm{sin}\left(x\right)$ and $\mathrm{cos}\left(x\right)$.

$\mathrm{plot}\left(\left[\mathrm{sin}\left(x\right),\mathrm{cos}\left(x\right)\right],x=-2\mathrm{\pi }..2\mathrm{π},\mathrm{tickmarks}=\left[\mathrm{spacing}\left(\mathrm{π},0\right),\mathrm{default}\right]\right)$

2. One period of the graphs of $\mathrm{sin}\left(x\right)$ and $\mathrm{cos}\left(x\right)$ with constrained scaling.

3. Labeling every $\frac{\mathrm{π}}{4}.$

For more information on tickmarks, including how to place one tickmark at a fixed location and then draw other tickmarks relative to that point, see plot/tickmarks.

4.  Using the Plot Builder to play with plot settings and preview the graph can be helpful with discontinuous graphs such as $y=\mathrm{tan}\left(x\right)$.  When satisfied, return the command.

$\mathrm{tan}\left(x\right)$$\to$${\mathrm{plot}}{}\left({\mathrm{tan}}{}\left({x}\right){,}{x}{=}{-}{10}{..}{10}{,}{\mathrm{discont}}{=}{\mathrm{true}}{,}{\mathrm{tickmarks}}{=}\left[{\mathrm{spacing}}{}\left({\mathrm{π}}{,}{0}\right){,}{\mathrm{default}}\right]{,}{\mathrm{view}}{=}\left[{\mathrm{DEFAULT}}{,}{-}{10}{..}{10}\right]\right)$

After returning the command from the Plot Builder, copy into a 2-D math region and execute.

$\mathrm{plot}\left(\mathrm{tan}\left(x\right),x=-10..10,\mathrm{discont}=\mathrm{true},\mathrm{tickmarks}=\left[\mathrm{spacing}\left(\mathrm{\pi },0\right),\mathrm{default}\right],\mathrm{view}=\left[\mathrm{DEFAULT},-10..10\right]\right)$



To learn more about the options shown here as well as other options accepted by the plot command, see plot/options.