 DocumentTools[Components] - Maple Programming Help

Home : Support : Online Help : Programming : Document Tools : Components : DocumentTools/Components/Plot

DocumentTools[Components]

 Plot
 generate XML for a Plot Component

 Calling Sequence Plot( p, opts )

Parameters

 p - (optional) ; a 2D or 3D plot, or the result from InlinePlot opts - (optional) ; one or more keyword options as described below

Options

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

Description

 • The Plot command in the Component Constructors package returns an XML function call which represents a Plot Component.
 • The generated XML may 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 may be inserted into the current document using the InsertContent command.

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Layout}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Components}\right):$

Executing the Plot command produces a function call.

 > $P≔\mathrm{Plot}\left(\mathrm{identity}="Plot0"\right)$
 {P}{≔}{\mathrm{_XML_EC-Plot}}{}\left({"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"}{=}{"\left[255,255,255\right]"}{,}{"visible"}{=}{"true"}\right) (1)

By using commands from the Layout Constructors package a nested function call can be produced which represents a worksheet.

 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(P\right)\right)\right)\right):$

That XML representation of a worksheet can be inserted directly.

 > $\mathrm{InsertContent}\left(\mathrm{xml}\right):$

 > $P≔\mathrm{Plot}\left(\mathrm{plot}\left(\mathrm{sin}\left(x\right),x=-\mathrm{\pi }..\mathrm{\pi }\right),\mathrm{identity}="Plot0",\mathrm{tooltip}="My example plot",\mathrm{pixelheight}=200\right):$
 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(P\right)\right)\right)\right):$

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.

 > $\mathrm{lookup}≔\mathrm{InsertContent}\left(\mathrm{xml},\mathrm{output}=\mathrm{table}\right)$
 ${\mathrm{lookup}}{≔}{table}{}\left(\left[{"Plot0"}{=}{"Plot1"}\right]\right)$ (2)

 > $\mathrm{lookup}\left["Plot0"\right]$
 ${"Plot1"}$ (3)
 > $\mathrm{GetProperty}\left(\mathrm{lookup}\left["Plot0"\right],\mathrm{visible}\right)$
 ${"true"}$ (4)

The next example makes use of action code for a Plot and a Button component.

 > $P≔\mathrm{Plot}\left(\mathrm{plot}\left(\left[\left[0,0\right]\right],\mathrm{color}=\mathrm{white},\mathrm{axes}=\mathrm{normal},\mathrm{view}=\left[0..10,0..10\right]\right),\mathrm{identity}="Plot0",\mathrm{clickdefault},\mathrm{clickaction}="update\left(%Plot0\right);"\right):$
 > $B≔\mathrm{Button}\left("Clear",\mathrm{identity}="Button0",\mathrm{action}="unassign\left(\text{'}:-L\text{'}\right); clear\left(%Plot0\right);"\right):$

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.

 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(B,P\right)\right)\right)\right)\right):$ 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 may be specified to match that of a parent Table Cell.

 > $P≔\mathrm{Plot}\left(\mathrm{identity}="Plot0",\mathrm{plot3d}\left({y}^{2}\mathrm{sin}\left(x\right),x=-\mathrm{\pi }..\mathrm{\pi },y=-2..2,\mathrm{axis}=\left[\mathrm{color}="DarkBlue"\right]\right),\mathrm{fillcolor}="LightGray",\mathrm{showborders}=\mathrm{false}\right):$\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Table}\left(\mathrm{alignment}=\mathrm{center},\mathrm{width}=380,\mathrm{widthmode}=\mathrm{pixels},\mathrm{Column}\left(\right),\mathrm{Row}\left(\mathrm{Cell}\left(\mathrm{Textfield}\left(P\right),\mathrm{fillcolor}="LightGray"\right)\right)\right)\right):
 > $\mathrm{InsertContent}\left(\mathrm{xml}\right):$

The following example programmatically inserts a PlotComponent with a scaled 3D animation which can be played using SetProperty.

 > $A≔\mathrm{plots}:-\mathrm{animate}\left(\mathrm{plot3d},\left[\mathrm{sin}\left(a{x}^{2}\right){y}^{2},x=-\mathrm{\pi }..\mathrm{\pi },y=-1..1,\mathrm{grid}=\left[200,50\right],\mathrm{labels}=\left["","",""\right],\mathrm{orientation}=\left[85,75,0\right],\mathrm{scaling}=\mathrm{constrained}\right],a=1.0..3.0,\mathrm{frames}=20\right):$
 > $P≔\mathrm{Plot}\left(\mathrm{identity}="MyAnim",\mathrm{showborders}=\mathrm{false},\mathrm{pixelwidth}=800,\mathrm{pixelheight}=400,\mathrm{InlinePlot}\left(A,\mathrm{scale}=2.7,\mathrm{width}=800,\mathrm{height}=400\right)\right):$\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Table}\left(\mathrm{alignment}=\mathrm{center},\mathrm{widthmode}=\mathrm{pixels},\mathrm{width}=720,\mathrm{Column}\left(\right),\mathrm{Row}\left(\mathrm{Cell}\left(\mathrm{Textfield}\left(P\right)\right)\right)\right)\right):
 > $\mathrm{tb}≔\mathrm{InsertContent}\left(\mathrm{xml},':-\mathrm{output}'=\mathrm{table}\right):$

 > $\mathrm{compnm}≔\mathrm{tb}\left["MyAnim"\right]$
 ${\mathrm{compnm}}{≔}{"MyAnim"}$ (5)
 > $\mathrm{DocumentTools}:-\mathrm{SetProperty}\left(\mathrm{compnm},\mathrm{play},\mathrm{true}\right)$
 > 

Compatibility

 • The DocumentTools:-Components:-Plot command was introduced in Maple 2015.