DocumentTools[Components]
Plot
generate XML for a Plot Component
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
Plot( p, opts )
p
-
(optional) ; a 2D or 3D plot, or the result from InlinePlot
opts
(optional) ; one or more keyword options as described below
captionalignment : identical(center,left,right):=center ; horizontal alignment of the component caption.
captionposition : identical(bottom,top):=bottom ; position of the component caption.
clickaction : string:=""; A string which parses to one or more valid statements in 1-D Maple Notation. These statements form the Click Action Component Code that executes when the Plot is clicked. The default is the empty string (no such action code).
clickdefault : truefalse:=false; Indicates whether the manipulator on a pointer click is to execute action code. The default value is false.
clickx : realcons; The initial x value of the click selector (as if the cursor were clicked).
clicky : realcons; The initial y value of the click selector (as if the cursor were clicked).
continuous : truefalse:=false ; Indicates whether the animation plays continuously or stops after displaying all the frames once.
delay : posint:=100 ; Delay in milliseconds between animation frames. The default value is 100.
dragendaction : string:=""; A string which parses to one or more valid statements in 1-D Maple Notation. These statements form the Drag End Action Component Code that executes when dragging the the pointer over the plot ends. The default is the empty string (no such action code).
drageventaction : string:=""; A string which parses to one or more valid statements in 1-D Maple Notation. These statements form the Dragged Action Component Code that executes when the pointer is dragged over the plot. The default is the empty string (no such action code).
drawcaption : truefalse:=false ; Indicates whether the component caption is shown. The caption on a PlotComponent is distinct from any caption in the contained plot, and is automatically generated by the graphical interface.
enabled : truefalse; Indicates whether the component is enabled. The default is true. If enabled is false then the inserted component is grayed out and interaction with it cannot be initiated.
endx : realcons:=0.0 ; The initial x value of the drag end selector, (as if a drag had ended).
endy : realcons:=0.0 ; The initial y value of the drag end selector, (as if a drag had ended).
pixelheight : posint; The height in pixels of the component.
fillcolor : {list(nonnegint),symbol,string}:=[255,255,255] ; 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.
hoveraction : string:=""; A string which parses to one or more valid statements in 1-D Maple Notation. These statements form the Hover Action Component Code that executes when the pointer hovers over the plot when in focus, if the component's Manipulator is set to Click and Drag. The default is the empty string (no such action code).
hoverx : realcons; The initial x value of the hover selector (as if the cursor were hovered).
hovery : realcons; The initial y value of the hover selector (as if the cursor were hovered).
identity : {name,string}; The reference name of the component.
legendvisibility : truefalse ; Indicates whether the legend is visible.
showborders : truefalse; Indicates whether component borders are shown
startx : realcons:=0.0 ; The initial x value of the drag start selector, (as if a drag had occurred).
starty : realcons:=0.0 ; The initial y value of the drag start selector, (as if a drag had occurred).
tooltip : string; The text that appears when the mouse pointer hovers over the component. The default is the empty string (no tooltip).
visible : truefalse; Indicates whether the component is visible. The default is true.
pixelwidth : posint; The width in pixels of the component.
The Plot command in the Component Constructors package returns an XML function call which represents a Plot Component.
The generated XML can be used with the results of commands in the Layout Constructors package to create an entire Worksheet or Document in XML form. Such a representation of a Worksheet or Document can be inserted into the current document using the InsertContent command.
with⁡DocumentTools:
with⁡DocumentTools:-Layout:
with⁡DocumentTools:-Components:
Executing the Plot command produces a function call.
P≔Plot⁡identity=Plot0
P≔_XML_EC-Plot⁡id=Plot0,captionalignment=1,captionposition=1,clickdefault=false,clickx=0.,clicky=0.,continuous=false,delay=100,drawcaption=false,enabled=true,endx=0.,endy=0.,hoverx=0.,hovery=0.,pixel-height=500,pixel-width=500,show-border=true,startx=0.,starty=0.,fillcolor=[255,255,255],visible=true
By using commands from the Layout Constructors package a nested function call can be produced which represents a worksheet.
xml≔Worksheet⁡Group⁡Input⁡Textfield⁡P:
That XML representation of a worksheet can be inserted directly.
InsertContent⁡xml:
P≔Plot⁡plot⁡sin⁡x,x=−π..π,identity=Plot0,tooltip=My example plot,pixelheight=200:
The previous example's call to the InsertContent command inserted a component with identity "Plot0", which still exists in this worksheet. Inserting additional content whose input contains another component with that same identity "Plot0" incurs a substitution of the input identity in order to avoid a conflict with the identity of the existing component.
The return value of the following call to InsertContent is a table which can be used to reference the substituted identity of the inserted component.
lookup≔InsertContent⁡xml,output=table
lookup≔table⁡Plot0=Plot1
lookupPlot0
Plot1
GetProperty⁡lookupPlot0,visible
true
The next example makes use of action code for a Plot and a Button component.
P≔Plot⁡plot⁡0,0,color=white,axes=normal,view=0..10,0..10,identity=Plot0,clickdefault,clickaction=update(%Plot0);:
B≔Button⁡Clear,identity=Button0,action=unassign(':-L'); clear(%Plot0);:
The action code passed with the clickaction option of the Plot component constructor calls a procedure update, and the action code of the Button component calls a procedure clear. These procedures are defined below. The update procedure uses the clickx and clicky values taken on when the mouse pointer is left clicked in the plot.
update := proc(comp) global L; local cx, cy, v; uses DocumentTools, plots, CurveFitting; (cx,cy) := Do(comp(clickx)), Do(comp(clicky)); if type(L,listlist) then L := [L[], [cx, cy]]; else L := [[cx, cy]]; end if; Do(comp = display(plot(L, style=point, symbol=solidcircle, symbolsize=15, color=blue, axes=normal), plot(LeastSquares(L, v), v=0..10), view=[0..10, 0..10])); end proc:
clear := proc(comp) DocumentTools:-Do(comp = plot([[0,0]], color=white, axes=normal, view=[0..10,0..10])); end proc:
Now we insert the components. Following insertion every single left click in the plot augments L with a new data point, and the plot is updated with a point plot and a least squares linear fit of the points in L.
InsertContent⁡Worksheet⁡Group⁡Input⁡Textfield⁡B,P:
The Plot component in the previous example is constructed by supplying identity="Plot0" as an option. But the first example on this page had already inserted content with a component with that identity. Hence the identity of the Plot component in the last example is replaced at insertion time. Note that literal instances of "Plot0" and Plot0 are also replaced in all component action code of the inserted content. The consistent replacement allows the action code to function as intended. Such replacement can be confirmed selecting the inserted Plot and Button components and viewing the component names in the Context Panel and then clicking the Edit Code buttons to view the Code Editor for these components.
The fillcolor can be specified to match that of a parent Table Cell.
P≔Plot⁡identity=Plot0,plot3d⁡y2⁢sin⁡x,x=−π..π,y=−2..2,axis=color=DarkBlue,fillcolor=LightGray,showborders=false:xml≔Worksheet⁡Table⁡alignment=center,width=380,widthmode=pixels,Column⁡,Row⁡Cell⁡Textfield⁡P,fillcolor=LightGray:
The following example programmatically inserts a PlotComponent with a scaled 3D animation which can be played using SetProperty.
A≔plots:-animate⁡plot3d,sin⁡a⁢x2⁢y2,x=−π..π,y=−1..1,grid=200,50,labels=,,,orientation=85,75,0,scaling=constrained,a=1.0..3.0,frames=20:
P≔Plot⁡identity=MyAnim,showborders=false,pixelwidth=800,pixelheight=400,InlinePlot⁡A,scale=2.7,width=800,height=400:xml≔Worksheet⁡Table⁡alignment=center,widthmode=pixels,width=720,Column⁡,Row⁡Cell⁡Textfield⁡P:
tb≔InsertContent⁡xml,:-output=table:
compnm≔tbMyAnim
compnm≔MyAnim
DocumentTools:-SetProperty⁡compnm,play,true
The DocumentTools:-Components:-Plot command was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
The DocumentTools:-Components:-Plot command was updated in Maple 2016.
The fillcolor option was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
See Also
Component Code
Component Constructors
DocumentTools
Embedded Components
Layout Constructors
XMLTools
Download Help Document