plot::easy – Easy plotting

plot::easy(arg, <Options>, ...) transforms data and expressions into graphical objects.

ATTENTION: Below the syntax #..., e.g. #Points, is used. Note that in MuPAD Pro 4 the syntax `#...`, e.g. `#Points`, must be used. Otherwise, MuPAD Pro 4 returns an syntax error message!

→ Examples

Call:

plot::easy(<arg, ...>, <Options>)

Parameters:

arg:

any object

Options:

#3D:

alias #3. Creates a 3D instead of a 2D scene, if possible. Usually, a 2D scene is created unless one of the arguments is a 3D object or can only be transformed into one.

#Arrows:

alias #A. Creates arrows instead of points. When used within a {...}-group, it affects the elements of this group or scene only.

#Constrained:

alias #C. Creates a coordinate system with axes having the same scaling. This is a shortcut for Scaling=Constrained.

#Grid:

alias #G. Creates a coordinate system with grid lines. This is a shortcut for GridVisible=TRUE.

#Legend:

alias #L. Creates a legend. This is a shortcut for LegendEntry=TRUE and LegendVisible=TRUE. When used within a {...}-group, it affects the elements of this group or scene only. Note that plot::easy explicitly sets a legend text for each graphical object it creates.

#Origin:

alias #O. Includes the coordinates (0,0) or (0,0,0), respectively, into the viewing box of the current scene.

#Points:

alias #P. Creates points instead arrows or curves. Furthermore, it sets the attributes PointsVisible=TRUE and LinesVisible=FALSE. When used within a {...}-group, it affects the elements of this group or scene only.

#XRange = a .. b:

alias #X = a .. b. Sets the x-range of the viewing box of the scene to a..b. This is a shortcut for ViewingBoxXRange=a..b.

#YRange = a .. b:

alias #Y = a .. b. Sets the y-range of the viewing box of the scene to a..b. This is a shortcut for ViewingBoxYRange=a..b.

#ZRange = a .. b:

alias #Z = a .. b. Sets the z-range of the viewing box of the scene to a..b. This is a shortcut for ViewingBoxZRange=a..b.

#<Colorname>:

If, and only if, RGB::<Colorname> is a valid color name in MuPAD, #<Colorname> is transformed to: Color=RGB::<Colorname>, LineColorType=Flat and for 3D objects additionally FillColorType=Flat. Transparent RGBa colors can be specified as #<Colorname>.[t], with t is in 0..1. When used within a {...}-group, it affects the elements of this group or scene only.

#<Colorname1> .. #<Colorname2>:

If, and only if, RGB::<Colorname1> and RGB::<Colorname2> are valid color names in MuPAD, this option is transformed to: Color=RGB::<Colorname1>, LineColorType=Dichromatic, LineColor2=RGB::<Colorname2> in 2D scenes and to: Color=RGB::<Colorname1>, FillColorType=Dichromatic, FillColor2=RGB::<Colorname2> in 3D scenes. Transparent RGBa colors can be specified as #<Colorname>.[t], with t is in 0..1. When used within a {...}-group, it affects the elements of this group or scene only.

Return Value:

A sequence of graphical objects and graphical attributes as well as objects that could not be transformed by plot::easy.

Overloaded by:

arg

Related Functions:

plot

Details:

plot::easy is still in an experimental state.

plot::easy accepts graphical objects and graphical attributes as input and returns them unchanged.

plot::easy supports the options listed above. Additionally, it accepts arbitrary data and expressions and tries to transform them into valid graphical objects.

The function plot calls plot::easy for preprocessing its input before plotting.

plot::easy tries to handle standard situations intuitively in order to make plotting as easy as possible. However, it supports only a small subset of the graphical objects, attributes and expressions available in MuPAD and thus does not claim to be complete.

Users that want to plot other objects or control specific details of their graphics explicitly, still have to create their graphical objects manually, e.g. using plot::Function2d and plot::Point2d, and to use graphical attributes like LineStyle=Dashed directly.

plot::easy sets a new color for each object that it creates, if no color is predefined in the given context.

plot::easy accepts sets {...} as group definition and transforms them into graphical objects of type plot::Group2d(...) or plot::Group3d(...), respectively. All elements of a group share the same color, if colors were not specified explicitly for single objects. Note that, regular graphical objects usually have a predefined color.

plot::easy accepts a nested set {{...}} as scene definition and transforms it into the graphical object plot::Scene2d(...) or plot::Scene3d(...), respectively.

Creating a graphical object may require the specification of value ranges for variables. If they are not specified explicitly then plot::easy tries use ranges specified for other variables and/or uses the default value range -5..5.

Example 1:

plot::easy tries to transform all given data and expressions into valid graphical objects and attributes:

plot::easy(sin(x), [PI/2,1])

math

Since the function plot calls the function plot::easy for preprocessing its input data, scenes like above can directly be plotted using plot:

plot(sin(x), [PI/2,1], #x=PI/2, #y=1)

MuPAD graphics

Now, it is only a small step to animate this scene:

plot(sin(x), {[x,sin(x)], #Points}, #x=x, #y=sin(x))

MuPAD graphics

Note: Graphical objects and attributes, as well as data that plot::easy cannot transform, are returned unchanged:

plot::easy(x, plot::Point2d(1,1), LineStyle=Dashed, "UnknownObject")

math

This is why plot returns the following error message when it is executed with the above arguments:

plot(x, plot::Point2d(1,1), LineStyle=Dashed, "UnknownObject");

Error: unexpected arguments: "UnknownObject" [plot::Canvas::new]

 

Example 2: Points

Points can be entered as lists with two or three values. Alternatively, a corresponding column vector in combination with the option #Points (alias #P, see example 18) can be used.

Note that for plotting animated points the option #Points is required. Otherwise a curve (when entered a list) or an arrow (when entered a vector) is plotted:

plot([0,1], [s,s^2], {[s,s^2], #Points}, s=-2.. 2,

     matrix([t,t^2]),  {matrix([t,t^2]), #Points}, t= 2..-2

)

MuPAD graphics

See also: plot::Point2d, plot::Point3d.

Example 3: Arrows

Arrows can be specified as column vectors with two or three elements. Alternatively, a list in combination with the option #Arrows (alias #A, see example 13) can be used:

plot(matrix([0,1]), matrix([s,s^2]), s=2..-2,

     [t,t^2], {[t,t^2], #Arrows}, t=-2..2

)

MuPAD graphics

If an arrow should start at coordinates other than (0,0) or (0,0,0), respectively, then a list of two column vectors or a corresponding list of lists in combination with the option #Arrows (alias #A, see example 13) can be used:

u:= matrix([3,2]):

v:= matrix([1,4]):

w:= (1-a)*u + a*v:

u, v, w;

math

plot(u, v, [u,w], a=0.1..1, #Arrows)

MuPAD graphics

delete u, v, w:

See also: plot::Arrow2d, plot::Arrow3d.

Example 4: Polygons

Polygons can be specified as lists, tables or matrices. In the following example, polygons are plotted using different input styles. The option #Origin (alias #O, see example 17) ensures that the origin of the coordinate system is visible in the scene as well:

plot([[1,3],[2,5],[3,3],[4,8]],

     table(1=4,2=6,3=4,4=9),

     [matrix([1,5]),matrix([2,7]),matrix([3,5]),matrix([4,10])],

     matrix([[1,6],[2,8],[3,6],[4,11]]),

     #Origin)

MuPAD graphics

Note that polygons are displayed as points when option #Points (alias #P, see example 18) is used:

plot([[1,3],[2,5],[3,3],[4,8]],

     table(1=4,2=6,3=4,4=9),

     [matrix([1,5]),matrix([2,7]),matrix([3,5]),matrix([4,10])],

     matrix([[1,6],[2,8],[3,6],[4,11]]),

     #Points, #Origin)

MuPAD graphics

Note that the following polygons with two elements are displayed as arrows when option #Arrows (alias #A, see example 13) is used:

plot([[1,4],[2,6]],

     [matrix([1,5]),matrix([2,7])],

     matrix([[1,6],[2,8]]),

     #Arrows, #Origin)

MuPAD graphics

See also: plot::Polygon2d, plot::Polygon3d.

Example 5: Point lists

Point lists can be specified as lists, tables or matrices. For each point an RGBa color has to be specified. In the following example, point lists are plotted using different input styles. The option #Origin (alias #O, see example 17) ensures that the origin of the coordinate system is visible in the scene as well:

plot([[1,2,RGB::Red], [2,4,[0,1,0]], [3,3,[0,0,1,0.5]]],

     [matrix([1,3,RGB::Red]),matrix([2,5,[0,1,0]]),matrix([3,4,[0,0,1,0.5]])],

     matrix([[1,4,RGB::Red], [2,6,[0,1,0]], [3,5,[0,0,1,0.5]]]),

     table(1=[5,RGB::Red], 2=[7,[0,1,0]], 3=[6,[0,0,1,0.5]]),

     #Origin)

MuPAD graphics

Note that the following point lists are displayed as arrows when option #Arrows (alias #A, see example 13) is used:

plot([[1,2,RGB::Red], [2,4,[0,1,0]] ,[3,3,[0,0,1,0.5]]],

     [matrix([1,3,RGB::Red]),matrix([2,5,[0,1,0]]),matrix([3,4,[0,0,1,0.5]])],

     matrix([[1,4,RGB::Red], [2,6,[0,1,0]], [3,5,[0,0,1,0.5]]]),

     table(1=[5,RGB::Red], 2=[7,[0,1,0]] ,3=[6,[0,0,1,0.5]]),

     #Arrows, #Origin)

MuPAD graphics

See also: plot::PointList2d, plot::PointList2d.

Example 6: Horizontal and vertical infinite lines and planes

For drawing horizontal and vertical infinite lines, the short syntax math and math with e is a real expression, can be used:

plot(sin(x), [PI/2,1], #x=PI/2, #y=1, #Legend)

MuPAD graphics

For drawing horizontal and vertical infinite planes, the short syntax math, math and math, with e is a real expression, can be used.

Both, lines and planes can also be animated:

plot([t,0,t^2], {[t,0,t^2], #Points}, #x=t, #z=t^2, #Legend)

MuPAD graphics

See also: plot::Line2d, plot::Plane.

Example 7: Curves

A curve can be specified as list with two or three elements, where at least one element depends on a free variable. If option #Points (alias #P, see example 18) is set, then instead of a curve, an animated point is plotted that moves along the curve.

plot([t,sin(t)], {[t,sin(t)], #Points},  t=0..2*PI)

MuPAD graphics

See also: plot::Curve2d, plot::Curve3d.

Example 8: Functions

plot::easy tries to transform expressions that are no lists, sets, matrices, equations or inequalities into graphs of 2D or 3D functions. We plot some graphs of 2D functions:

plot(sin(x), tan(x), x)

MuPAD graphics

We plot a simple 3D function. Note that the option #3D (alias #3, see example 12) is required in the following example for plotting a 3D function. Otherwise, an animated 2D function is created.

plot(m*x, #3D)

MuPAD graphics

We plot a simple 2D animation: a point and the correpsonding tangent of the sine function move along the sine function graph:

f:= x -> sin(x):

plot(f(x), x = -PI..PI,

     {[a, f(a)], #Points}, f'(a)*(x-a) + f(a), a = -PI/2..PI/2)

MuPAD graphics

We plot a piecewise defined function:

plot(piecewise([x < 1, -x^2 + 1], [x >= 1, x + 5]), #x=1, #Legend)

MuPAD graphics

The same piecewise defined function is now written in a shorter syntax. Note the difference between defining one function with two branches (left) and defining two functions (right):

plot({{[[x < 1, -x^2 + 1], [x >= 1, x + 5]], #x=1}},

     {{ [x < 1, -x^2 + 1], [x >= 1, x + 5] , #x=1}},

     #Legend)

MuPAD graphics

See also: plot::Function2d, plot::Function3d.

Example 9: Implicit functions

An implicit function can be specified as an equation:

plot(u^5 + x^2 = 1 - u^3)

MuPAD graphics

Note that the option #3D (alias #3, see example 12) may be required to plot planes given as cartesian equations. Otherwise, an animated 2D graph might be created. This depends on the number of variable of the equation.

E1:= 2*x + 30*y - 2*z = 5:

E2:= -x + 7*y - z = 12:

E3:= -4*x + 2*y + z = 0:

plot(E1, E2, E3, #3D, #Legend)

MuPAD graphics

delete E1, E2, E3:

See also: plot::Implicit2d, plot::Implicit3d.

Example 10: Inequalities

An inequality can be displayed directly:

plot(u^5+x^2 < 1-u^3)

MuPAD graphics

The same is true for a list of inequalities and equations:

plot([x < 3, x > 1, y <  4, y > -4])

MuPAD graphics

See also: plot::Inequality.

Example 11: Texts

To display a 2D text at a certain position, an equation of a coordinate tuple and a character string or a procedure can be entered:

plot([t, t^2],

    {[t, t^2], #Points},

     [t, t^2] = "moving text")

MuPAD graphics

We display a 3D text. As in any other context of plot::easy, we can use regular graphical attributes like TextFont=Center as well:

DIGITS := 2:

plot([t, t^2, 1],

    {[t, t^2, 1], #Points},

     [t, t^2, 1] = (t->" x = ".[t, t^2, 1.0]),

     TextFont=[Bold]):

delete DIGITS:

MuPAD graphics

See also: plot::Text2d, plot::Text3d.

Example 12: Option #3D (alias #3)

Usually plot::easy creates a 2D scene, unless one of the arguments is a 3D object or can only be transformed to a 3D object or the option #3D is used.

plot(sin(x), #3)

MuPAD graphics

However, the option #3D is only a hint. It is ignored if the current scene can only be a 2D scene. In the following example, the 2D point determines the dimension of the scene:

plot([PI/2,1], sin(x), #3)

MuPAD graphics

In the following example, the 3D point determines the dimension of the scene. There is no need to use option #3D in order to create a 3d scene:

plot([PI/2,1,0], sin(x))

MuPAD graphics

Example 13: Option #Arrows (alias #A)

With option #Arrows, arrows instead of points or curves are created. When used within a {...}-group, it affects the elements of this group or scene only.

plot({{ [-5,25], [5,25], [x,x^2]     }},

     {{ [-5,25], [5,25], [x,x^2], #A }})

MuPAD graphics

Example 14: Option #Constrained (alias #C)

Option #Constrained creates a coordinate system with constrained scaled axes. This is a shortcut for Scaling = Constrained.

plot({{ x^2 }}, {{ x^2, #C }})

MuPAD graphics

Example 15: Option #Grid (alias #G)

Option #Grid creates a coordinate system with grid lines. This is a shortcut for GridVisible = TRUE.

plot({{ x^2 }}, {{ x^2, #G }})

MuPAD graphics

Example 16: Option #Legend (alias #L)

Option #Legend creates a legend. This is a shortcut for LegendVisible = TRUE in combination with LegendEntry = TRUE. Note that plot::easy explicitly sets a legend text for each graphical object it creates.

plot([0,-6], x^2-5, [t,t^2], #L)

MuPAD graphics

Example 17: Option #Origin (alias #O)

Option #Origin includes the coordinates (0,0) or (0,0,0), respectively, into the viewing box of the current scene.

plot({{[2,2], [3,3]}}, {{[2,2], [3,3], #O}})

MuPAD graphics

Example 18: Option #Points (alias #P)

Using option #Points, points instead of arrows or curves are created. Furthermore, this option sets the attributes PointsVisible=TRUE and LinesVisible=FALSE. When used within a {...}-group, it affects the elements of this group or scene only.

plot({[-5,25], [x,x^2], #Gray}, {matrix([5,25]), [x,x^2], #P})

MuPAD graphics

Example 19:  Options #XRange (#X), #YRange (#Y), #ZRange (#Z)

#X / #Y / #Z = a..b sets the x- / y- / z-range of the viewing box of the scene to a..b. This is a shortcut for ViewingBoxXRange / ViewingBoxYRange / ViewingBoxZRange = a..b.

plot({{x^2, sin(x)}}, {{x^2, sin(x), #Y=0..4}})

MuPAD graphics

We draw a 3D scene with a restricted viewing box. Therefore, only a quater of the shere is visible:

plot({{plot::Sphere(1)}},

     {{plot::Sphere(1), #X=0..1, #Y=0..1, #Z=0..1}})

MuPAD graphics

Background:

Let ci be real constants and f and fi be real functions.

plot::easy automatically carries out the following transformations:

Graphical object

Data or mathematical expression

plot::Point2d:

[c1, c2], {[math, math], #Points}, {matrix([math, math]), #Points}.

plot::Point3d:

[c1, c2, c3], {[math, math, math], #Points}, {matrix([math, math, math]), #Points}.

plot::Arrow2d:

matrix([c1, c2]), {[c1, c2], #Arrows}, {[matrix([math, math]), matrix([math, math])], #Arrows}, {matrix([[math, math], [math, math]]), #Arrows}, {[[math, math], [math, math]], #Arrows}.

plot::Arrow3d:

matrix([c1, c2, c3]), {[c1, c2, c3], #Arrows}, {[matrix([math, math, math]), matrix([math, math, math])], #Arrows}, {matrix([[math, math, math], [math, math, math]]), #Arrows}, {[[math, math, math], [math, math, math]], #Arrows}.

plot::Polygon2d:

[[math, math],...], [matrix([math, math]),...], matrix([[math, math],...]), table(math=math,...).

plot::Polygon3d:

[[math, math, math],...], [matrix([math, math, math]),...], matrix([[math, math, math],...]). table(math=[math, math],...).

plot::PointList2d:

[[math, math, RGBa],...], [matrix([math, math, RGBa]),...], matrix([[math, math, RGBa],...]), table(math=[math, RGBa],...).

plot::PointList3d:

[[math, math, math, RGBa],...], [matrix([math, math, math, RGBa]),...], matrix([[math, math, math, RGBa],...]). table(math=[math, math, RGBa],...).

plot::Line2d:

#x=math, #y=math.

plot::Plane:

#z=math, {#x=math, #3D}, {#y=math, #3D}, {#z=math, #3D}.

plot::Curve2d:

[math, math].

plot::Curve3d:

[math, math, math].

plot::Function2d:

math, math, math, [math,...].

plot::Function3d:

math, math, [math,...], {math, #3D}, {math, #3D}.

plot::Implicit2d:

math=math.

plot::Implicit3d:

math=math, {math=math, #3D}.

plot::Inequality:

math, math, math, math, [math<math, math>math, math=math,...].

plot::Text2d:

[math, math]=text, matrix([math, math])=text, [math, math]=procedure, matrix([math, math])=procedure.

plot::Text3d:

[math, math, math]=text, matrix([math, math, math])=text, [math, math, math]=procedure, matrix([math, math, math])=procedure.