Click and Drag - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Plot Component

insert a plot region in a worksheet or document

 

Description

Assigning a Plot Command to a Plot Component

Component Palette Image

Plot Properties

Plot Component Examples

Description

• 

The plot component displays a 2-D or 3-D plot. 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.

• 

For 2-D plots, 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.

• 

To program the worksheet to perform an action when a 2-D plot is clicked or dragged, click the 2-D plot, and then select the menu item in the Context Panel 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 Code - performs an action when the mouse clicks a plot

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

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

Edit Hover Code - performs an action when the mouse hovers in a 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: To interact with the plot, you need to use the click and drag manipulator tool ( ).  Ensure the Execute click and drag code icon, , is selected in the Plot toolbar. You can also set this to be the default for the plot component: select the Click and Drag Manipulator check box in the Plot context panel.  Now, whenever the document containing this plot component is opened, the click and drag tool is selected.

• 

The plot component is customized by setting options in the Plot context panel. To view the Plot context panel select the plot component. 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 context panel.

It is possible to set the Plot Expression to a command string by using double quotes around the command, for example:

DocumentTools[SetProperty]("Plot0", value, "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 Get column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.

  

An x in the Set column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.

  

 

Option

Get

Set

Option Type

clickdefault

x

x

true or false

clickx

x

 

floating-point number

clicky

x

 

floating-point number

codeclick

x

x

string

codedrag

x

x

string

codedragend

x

x

string

codehover

x

x

string

continuous

 

x

true or false

delay

x

x

positive integer

endx

x

 

floating-point number

endy

x

 

floating-point number

extents

x

 

list of floats [xmin,ymin,ymax,ymax]

fillcolor

x

x

color

frame

x

x

positive integer

framebackwards

 

x

true or false

framecount

x

 

positive integer

frameforwards

 

x

true or false

hoverx

x

 

floating-point number

hovery

x

 

floating-point number

mousemode

x

x

one of: probe, rotate, translate, click_and_drag, scale_zoom_in, scale_zoom_out

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

type

x

 

string

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.   

  

codeclick 

  

The action code that is executed when the plot is clicked on (with the plot manipulator cursor).

  

codedrag 

  

The action code that is executed when dragging over a plot with the mouse button pressed (with the plot manipulator cursor).

  

codedragend 

  

The action code that is executed when releasing the mouse after dragging on a plot (with the plot manipulator cursor).

  

codehover 

  

The action code that is executed when the cursor hovers over a plot (with the plot manipulator cursor).

  

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.

  

extents 

  

Returns the extents of the plot view as a list of floating-point numbers, [xmin,ymin,xmax,ymax], where [xmin,ymin] are the coordinates of the lower left corner, and [xmax,ymax] are the coordinates of the upper right corner.  This is a read-only option, and cannot be set.

  

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.

  

mousemode 

  

Sets the plot manipulator for the plot. The possible values are probe, rotate (3-D plots only), translate, click_and_drag (2-D plots only), scale_zoom_in, and scale_zoom_out.

  

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 500.

  

pixelwidth 

  

The width of the plot in pixels. By default, the value is 500.

  

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.

  

type 

  

The type of the component. This returns "Plot".

  

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. 

Select the Plot component to display the Plot context panel.

3. 

In the Plot Expression field, enter:
plot3d(x^2*cos(y), x=-1..1, y=-2*Pi..2*Pi);

 

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. 

Select the Plot component to display the context panel.

3. 

In the Plot Expression field, enter plot(sin(x), x=0..10);

 

To add items to the combo box:

1. 

Click 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.

 

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

1. 

Select the ComboBox component, and then select Edit Select Code.

This launches the Code Editor dialog.

2. 

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

SetProperty("Plot1", value, plot(parse(GetProperty("ComboBox0", value)), x=0..10));

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

3. 

Click  or 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.

  

  

 

 

with(DocumentTools):

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

SetProperty("Plot1", value, plot(parse(GetProperty("ComboBox0", value)), 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. 

Select the Plot component, and then select Edit Click Code.

This launches the Code Editor dialog.

3. 

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

cx := GetProperty("Plot2", clickx);
cy := GetProperty("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);

SetProperty("Plot2", value, plots[display]({G, H}));

Notes:

• 

Ensure the component name (that is, Plot2) is correct and matches the Name field in the context panel .

• 

cx := GetProperty("Plot2", clickx);
cy := GetProperty("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. 

Click  or from the File menu, select Save Code to accept all changes.

5. 

From the File menu, select Close Code Editor.

6. 

Select the Plot component, and from the context panel, select Click and Drag Manipulator.

 

To configure the button to clear the plot region:

1. 

Click the Button component, and then select Edit Click Code.

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:

SetProperty("Plot2", value, 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.

3. 

From the File menu, select Save Code to accept all changes.

4. 

From the File menu, select Close Code Editor.

5. 

Click the Button component to display the Button context panel.

6. 

In the Caption field, enter Clear Plot.

7. 

Click on the Plot component.

8. 

From the Plot toolbar, click Execute click and drag code ( ).

9. 

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

Building an Interactive Number Line

See Also

DocumentTools

DocumentTools[GetProperty]

DocumentTools[SetProperty]

EmbeddedComponents

Maplets[Elements][Plotter]

plot

plot3d

Toolbar for 2-D Plots