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
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.
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.
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
true or false
clickx
floating-point number
clicky
codeclick
string
codedrag
codedragend
codehover
continuous
delay
positive integer
endx
endy
extents
list of floats [xmin,ymin,ymax,ymax]
fillcolor
color
frame
framebackwards
framecount
frameforwards
hoverx
hovery
mousemode
one of: probe, rotate, translate, click_and_drag, scale_zoom_in, scale_zoom_out
pause
pixelheight
pixelwidth
play
showborders
startx
starty
`stop`
toend
tooltip
tostart
type
value
plot command
visible
Indicates whether the default cursor action on a plot component is a click action.
The x-coordinate of the position where the mouse click occurs.
The y-coordinate of the position where the mouse click occurs.
The action code that is executed when the plot is clicked on (with the plot manipulator cursor).
The action code that is executed when dragging over a plot with the mouse button pressed (with the plot manipulator cursor).
The action code that is executed when releasing the mouse after dragging on a plot (with the plot manipulator cursor).
The action code that is executed when the cursor hovers over a plot (with the plot manipulator cursor).
Indicates if the animation plays continuously or stops after displaying all the frames once.
Delay in milliseconds between frames. By default, the value is 100.
Indicates the x-coordinate of the current position of the mouse during the drag.
Indicates the y-coordinate of the current position of the mouse during the drag.
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.
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.
The currently displayed frame.
Setting this option to true displays the previous frame in sequence. If the animation is in progress, it stops.
The number of currently displayed frames.
Setting this option to true displays next frame in sequence. If the animation is in progress, it stops.
The x-coordinate of the position where the mouse is currently hovering.
The y-coordinate of the position where the mouse is currently hovering.
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.
Equivalent to stop. Setting this option to true pauses the animation. Setting this option to false starts the animation.
The height of the plot in pixels. By default, the value is 500.
The width of the plot in pixels. By default, the value is 500.
Setting this option to true starts the animation or resumes a paused animation. Setting this option to false stops the animation.
Specifies if the border of the component is visible. By default, the value is true.
The x-coordinate of the position at the start of the drag movement.
The y-coordinate of the position at the start of the drag movement.
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.
Setting this option to true displays the last frame in the sequence. If the animation is in progress, it stops.
The text that appears when hovering the mouse over the component.
Setting this option to true displays the first frame in the sequence. If the animation is in progress, it stops.
The type of the component. This returns "Plot".
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.
Specifies if the plot component is visible. By default, the value is true.
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.
Insert a Plot component using the Components palette. For information on displaying the Maple palettes, see the Show Palettes help page.
Select the Plot component to display the Plot context panel.
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:
Insert a Plot component and a Combo Box component into your worksheet.
Select the Plot component to display the context panel.
In the Plot Expression field, enter plot(sin(x), x=0..10);
To add items to the combo box:
Click the ComboBox component, and then select Component Properties.
Click the Edit button of Item List field.
Double-click the first row, and then replace ComboBox with sin(x).
Click Add, double-click the newly added field, and then replace the default entry with cos(x).
Click Add, double-click the newly added field, and then replace the default entry with tan(x).
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:
Select the ComboBox component, and then select Edit Select Code.
This launches the Code Editor dialog.
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).
Click or from the File menu, select Save Code to accept all changes.
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)
with(DocumentTools):
You can verify the syntax of the embedded component action by executing the command in the worksheet.
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:
Insert a Plot and a Button component into your worksheet.
Select the Plot component, and then select Edit Click Code.
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.
Select the Plot component, and from the context panel, select Click and Drag Manipulator.
To configure the button to clear the plot region:
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.
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.
From the File menu, select Save Code to accept all changes.
Click the Button component to display the Button context panel.
In the Caption field, enter Clear Plot.
Click on the Plot component.
From the Plot toolbar, click Execute click and drag code ( ).
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
Download Help Document