Plot Component - Maple Programming Help

Home : Support : Online Help : Programming : Document Tools : Embedded Components : PlotComponent

Plot Component

Insert a plot region in a Standard Maple worksheet or document.

Description

 • The plot component performs an action or a series of actions to communicate with other embedded components when the plot is clicked or dragged, although assigning an action to a component is not required.  Note: Actions can only take place for 2-D plots.
 • The plot component offers similar capabilities as a plot region in a Maple worksheet. For example, plot options can be applied using the context menus or the Plot toolbar, and 3-D plots can be rotated.
 • To perform an action when a 2-D plot is clicked or dragged, right-click (Control-click for Macintosh) the 2-D plot, and then select the menu item for the event (that is, click or drag) that you are interested in. This opens the Code Editor dialog for the event selected. The available choices are:

Edit Click Action - performs an action when the mouse clicks a plot

Edit Drag End Action - performs an action when the mouse is released from dragging in a plot component

Edit Dragged Action - performs an action when the mouse is dragged in the plot component

Enter the commands you want to perform in the Code Editor dialog.

 • In your commands you need to specify one or more embedded components that will display the output of the action. For more information, see the Plot Component Examples on this page.

Note: These actions will only take place if the Execute click and drag code icon, , is selected in the Plot toolbar or the Plot menu. You can also select the Make Click and Drag the default manipulator check box in the Plot Properties to set this default when the worksheet or document is opened.

 • The plot component is customized by setting options in the Plot Properties. To open the Plot Properties, right-click (Control-click for Macintosh) the plot component, and then select Component Properties. Actions are associated with components using routines in the DocumentTools package.
 • The Name property is used to reference the plot when using the routines from the DocumentTools package.
 Assigning a Plot Command to a Plot Component When the 'value' of a plot component is set to a plot command using Do or SetProperty, the plot command is evaluated before it is sent to the plot component.  The result of this evaluation is an internal plot structure.  This structure is set to be the value of the plot component.  This structure is not editable by the user, and the user will see a blank string as the Plot Expression in the Component Properties dialog. It is possible to set the Plot Expression to a command string by using double quotes around the command, for example, DocumentTools[Do](%Plot0="plot(sin(x),x=0..10)"); This approach is not recommended; substitution of the values of the component does not take place within quoted strings in a Do statement, and thus will not be recognized.
 Component Palette Image

Plot Properties

 • The following table describes the control and use of the plot component options.
 An x in the G column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.
 An x in the S column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.

Option         G  S  Option Type

clickdefault   x  x  true or false
clickx         x     floating-point number
clicky         x     floating-point number
continuous        x  true or false
delay          x  x  positive integer
endx           x     floating-point number
endy           x     floating-point number
fillcolor      x  x  color

frame          x  x  positive integer
frameBackwards    x  true or false
frameCount     x  x  positive integer
frameForwards     x  true or false
hoverx         x     floating-point number

hovery         x     floating-point number

pause             x  true or false
pixelHeight    x  x  positive integer
pixelWidth     x  x  positive integer
play              x  true or false
showBorders    x  x  true or false
startx         x     floating-point number
starty         x     floating-point number
stop            x  true or false
toEnd             x  true or false
tooltip        x  x  string
toStart           x  true or false
value          x  x  plot command
visible        x  x  true or false

 clickdefault
 Indicates whether the default cursor action on a plot component is a click action.
 clickx
 The x-coordinate of the position where the mouse click occurs.
 clicky
 The y-coordinate of the position where the mouse click occurs.
 continuous
 Indicates if the animation plays continuously or stops after displaying all the frames once.
 delay
 Delay in milliseconds between frames. By default, the value is 100.
 endx
 Indicates the x-coordinate of the current position of the mouse during the drag.
 endy
 Indicates the y-coordinate of the current position of the mouse during the drag.
 fillcolor
 Specifies the background color of the component. The passed value can be either a named color or a list of three integers each between 0 and 255. A list of nonnegative integers is interpreted as RGB values in a 24bit 3-channel color space. The default value is [255,255,255] which corresponds to white.
 frame
 The currently displayed frame.
 frameBackwards
 Setting this option to true displays the previous frame in sequence. If the animation is in progress, it stops.
 frameCount
 The number of currently displayed frames.
 frameForwards
 Setting this option to true displays next frame in sequence. If the animation is in progress, it stops.
 hoverx
 The x-coordinate of the position where the mouse is currently hovering.
 hovery
 The y-coordinate of the position where the mouse is currently hovering.
 pause
 Equivalent to stop. Setting this option to true pauses the animation. Setting this option to false starts the animation.
 pixelHeight
 The height of the plot in pixels. By default, the value is 400.
 pixelWidth
 The width of the plot in pixels. By default, the value is 400.
 play
 Setting this option to true starts the animation or resumes a paused animation. Setting this option to false stops the animation
 showBorders
 Specifies if the border of the component is visible. By default, the value is true.
 startx
 The x-coordinate of the position at the start of the drag movement.
 starty
 The y-coordinate of the position at the start of the drag movement.
 stop
 Setting this option to true stops the animation. Setting this option to false starts the animation. Because (stop) is also a keyword, you must use left single quotes ( ) to refer to this property.
 toEnd
 Setting this option to true displays the last frame in the sequence. If the animation is in progress, it stops.
 tooltip
 The text that appears when hovering the mouse over the component.
 toStart
 Setting this option to true displays the first frame in the sequence. If the animation is in progress, it stops.
 value
 Value to be displayed (a Maple plot structure). This can be the output of plot, plot3d, or any other plotting routine, or any user-defined PLOT or PLOT3D plot structure.
 visible
 Specifies if the plot component is visible. By default, the value is true.

Plot Component Examples

Note: To interact with the examples provided below, open this help page as a worksheet and then execute the worksheet.

Example 1 - Display a plot in the Plot component.

 1 Insert a Plot component using the Components palette. For information on displaying the Maple palettes, see the Show Palettes help page.
 2 Right-click (Control-click for Macintosh) the Plot component, and then select Component Properties.
 3 In the Plot Expression field, enter plot3d(x^2*cos(y), x=-1..1, y=-2*Pi..2*Pi); and accept this setting.
 4 Click OK to accept this new setting.

Example 2 - Select a function from a combo box and display a plot of that function using embedded components.

To insert the components and configure the plot component:

 1 Insert a Plot component and a Combo Box component into your worksheet.
 2 Right-click (Control-click for Macintosh) the Plot component, and then select Component Properties.
 3 In the Plot Expression field, enter plot(sin(x), x=0..10);.
 4 Click OK.

To add items to the combo box:

 1 Right-click (Control-click for Macintosh) the ComboBox component, and then select Component Properties.
 2 Click the Edit button of Item List field.
 3 Double-click the first row, and then replace ComboBox with sin(x).
 4 Click Add, double-click the newly added field, and then replace the default entry with cos(x).
 5 Click Add, double-click the newly added field, and then replace the default entry with tan(x).
 6 Click OK to close the List Editor.
 7 Click OK to close the ComboBox Properties.

To retrieve the expression from the combo box and display a plot of the expression in the plot component:

 1 Right-click (Control-click for Macintosh) the ComboBox component, and then select Edit Select Action.

This launches a dialog with preset statements and additional information on how to program actions between embedded components.

 2 Before the end use; statement in the dialog, enter the following command:

Do(%Plot1=plot(%ComboBox0, x=0..10));

Note: Ensure the names of the components are correct (that is, that they match the Name fields for their components).

 3 From the File menu, select Save Code to accept all changes.
 4 From the File menu, select Close Code Editor.

When you select an item from the combo box, the expression selected is displayed in the plot component.

 sin(x)cos(x)tan(x)

You can verify the syntax of the embedded component action by executing the command in the worksheet.

 > DocumentTools[Do](%Plot1 = plot(sin(x), x = 0..10));

Example 3 - Use a plot region to generate and display a least squares approximation of the plot data points. Data points are retrieved from the x and y coordinates of mouse clicks on the plot region. A button component is used to clear the plot.

To insert the components and configure the plot region:

 1 Insert a Plot and a Button component into your worksheet.
 2 Right-click (Control-click for Macintosh) the Plot component, and then select Edit Click Action.

This launches a dialog with preset statements and additional information on how to program actions between embedded components.

 3 Before the end use; statement, enter the following commands:

Do(cx = %Plot2(clickx));

Do(cy = %Plot2(clicky));

if(type(L,listlist)) then

L := [L[], [cx, cy]];

else

L:=[[cx,cy]];

end if;

G := plot(L, style = point, symbol = solidcircle, color = blue, symbolsize = 15, view = [0 .. 10, 0 .. 10], axes = normal);

H := plot(CurveFitting:-LeastSquares(L, v), v=0..10);

Do(%Plot2 = plots[display]({G, H}));

Notes:

 • Ensure the component name (that is, Plot2) is correct and matches the Name field in Plot Properties.
 • Do(cx = %Plot2(clickx)); and Do(cy = %Plot2(clicky));  retrieve the x and y coordinates of the position where the mouse click occurs and assigns these values to to cx and cy, respectively.
 4 From the File menu, select Save Code to accept all changes.
 5 From the File menu, select Close Code Editor.
 6 Right-click (Control-click for Macintosh) the Plot component, and then select Component Properties.
 7 Select Make Click and Drag the default manipulator.
 8 Click OK.

To configure the button to clear the plot region:

 1 Right-click (Control-click for Macintosh) the Button component, and then select Edit Click Action.

This launches a dialog with the same preset statements as in the plot component dialog.

 2 Before the end use; statement in the dialog, enter the following commands:

Do(%Plot2 = plot([[0, 0]], x=0..10, y=0..10, style=point, axes=normal, view=[0..10, 0..10], color=white));

L := [];

Note: Ensure the component name (that is, Plot2) is correct and matches the Name field in Plot Properties.

 3 From the File menu, select Save Code to accept all changes.
 4 From the File menu, select Close Code Editor.
 5 Right-click (Control-click for Macintosh) the Button component, and then select Component Properties.
 6 In the Caption field, enter Clear Plot.
 7 Click OK to accept all changes.
 8 Click on the Plot component.
 9 From the Plot toolbar, click Execute click and drag code ( ).
 10 Click Clear Plot.

When you click on a point in the plot region, a blue dot displayed at that point as well as a straight line representing the least squares approximation for your data.

 Applications