MaplePortal/UnitsInPlots - Help

Using Units in Plots

 Introduction Maple allows you to create both 2-D and 3-D plots with units. The units can be supplied in the function, ranges, or as an option. The axis labels will display the unit information deduced from the arguments.

Units in 2-D Plots

You can add units from the Units palette to an expression that is graphed with the plot command.

Example: In this example, units are added to the $x$-range and the expression.

$\mathrm{plot}\left(\mathrm{sin}\left(x\right)⟦m⟧,x=0..2\cdot \mathrm{π}⟦\mathrm{rad}⟧\right)$

You can create a plot with units interactively by using the Context Panel on an expression with units.

Example: From the Context Panel for the expression, select Plots>2-D Plot.

$\to$

You can also add units with the 'useunits' option. With this option, the units are given in a list useunits=[units for $x$, units for $y$].

Example:

$\mathrm{plot}\left({\mathrm{sin}}^{2}\left(x\right)\cdot x,x=0..2\cdot \mathrm{π},\mathrm{useunits}=\left[⟦\mathrm{min}⟧,⟦m⟧\right],\mathrm{color}="Blue"\right)$

Instead of using the palette, you can add units with the Unit command.

Example:$\mathrm{plot}\left(-{x}^{3}+5{x}^{2},x=0..5,\mathrm{useunits}=\left[\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{Unit}\left(m\right)\right],\mathrm{color}="Chocolate"\right)$

Plotting Expressions versus Procedures with Units

You can create a graph with units from an expression or a procedure. See the help page plot/details for more information.

When you plot an expression, the axes labeling shows the variable names and units. This is shown in the following example (as well as all the earlier examples).

Example:

$\mathrm{trange}≔0..4⟦s⟧:$

$\mathrm{yrange}≔0..3⟦\mathrm{ft}⟧:$

$\mathrm{plot}\left(a,t=\mathrm{trange},y=\mathrm{yrange}\right)$

When you plot a procedure, such as the function $h$ defined here, no variable names are used.

Example:

$\mathrm{plot}\left(h,\mathrm{trange},\mathrm{yrange}\right)$

Note: To plot a procedure that contains units, you must tell the plotting command that units are involved so that the procedure is properly processed. For computational efficiency, when a procedure is plotted, the values returned from the procedure are assumed to be unit-free by default. Therefore, if your procedure returns a numeric value with units, you must specify to the plotting command that units are involved. You can specify this by including units in the ranges or by using setting the option useunits=true (or simply useunits).   See the help page Plots with Units for details.

Example: Specify that units are involved in the procedure by using units in the ranges.

$\mathrm{plot}\left(x\to {x}^{2}⟦m⟧,-5..5⟦s⟧,0..25⟦m⟧,\mathrm{thickness}=2,\mathrm{color}="DarkGreen"\right)$

Alternatively, indicate that the procedure returns units by using the useunits option. The first example simply indicates that the procedure involves units, while the second example specifies units to be displayed on the axes.

$\mathrm{plot}\left(x→{x}^{2}⟦m⟧,-5..5,\mathrm{useunits},\mathrm{thickness}=2,\mathrm{color}="DarkGreen"\right)$

$\mathrm{plot}\left(x→{x}^{2}⟦m⟧,-5..5,\mathrm{useunits}=\left[⟦s⟧,⟦m⟧\right],\mathrm{thickness}=2,\mathrm{color}="DarkGreen"\right)$

To make further modifications to any plot, you can use options to the plot command, or make modifications interactively by clicking on the plot and using the Edit > Plot menu options.

Units in 3-D Plots

The plot3d command recognizes units similarly to the plot command.

Example:

$\mathrm{plot3d}\left(\mathrm{sin}\left(x\right)\cdot \left(y-1\right),x=0..4\cdot \mathrm{π},y=0..2,\mathrm{useunits}=\left[⟦s⟧,⟦\mathrm{kg}⟧,⟦\frac{{m}^{2}}{\mathrm{kg}}⟧\right]\right)$