Skip to Main Content Skip to Search
Product Documentation

The Full Picture: Graphical Trees

For a full understanding of the interactive features of the viewer to be discussed in the next section, we need to know the structure of a MuPAD® plot as a “graphical tree.”

The root is the “canvas”; this is the drawing area into which all parts of the plot are rendered. The type of the canvas object is plot::Canvas. Its physical size may be specified via the attributes Width and Height.

Inside the canvas, one or more “graphical scenes” can be displayed. All of them must be of the same dimension, i.e., objects of type plot::Scene2d or plot::Scene3d, respectively. The following command displays four different 3D scenes. We set the BorderWidth for all objects of type plot::Scene3d to some positive value so that the drawing areas of the scenes become visible more clearly:

plot(plot::Canvas(
  plot::Scene3d(plot::Sphere(1, [0, 0, 0], Color = RGB::Red),
                BackgroundStyle = LeftRight),
  plot::Scene3d(plot::Box(-1..1, -1..1, -1..1,
                          Color = RGB::Green),
                BackgroundStyle = TopBottom),
  plot::Scene3d(plot::Cone(1, [0, 0, 0], [0, 0, 1],
                           Color = RGB::Blue),
                BackgroundStyle = Pyramid),
  plot::Scene3d(plot::Cone(1, [0, 0, 1], [0, 0, 0],
                           Color = RGB::Orange),
                BackgroundStyle = Flat,
                BackgroundColor = RGB::Grey),
  Width = 80*unit::mm, Height = 80*unit::mm,
  Axes = None, BorderWidth = 0.5*unit::mm,
  plot::Scene3d::BorderWidth = 0.5*unit::mm
)):

MuPAD graphics

See section Layout of Canvas and Scenes for details on how the layout of a canvas containing several scenes is set.

Coordinate systems of type plot::CoordinateSystem2d or plot::CoordinateSystem3d exist inside a 2D scene or a 3D scene, respectively. There may be one or more coordinate systems in a scene. Each coordinate system has its own axes. In the following example, we place two coordinate systems in one scene. The first is used to display the sales of apples in the years 1998 through 2003 in units of 1000 tons, the second is used to display the sale of cars in units of 10.000 cars. The y-axis for the apples is “flushed left” by setting the x component of its origin to the first year 1998, whilst the y-axis for the cars is “flushed right” by setting the x component of its origin to the last year 2003:

apples := plot::Polygon2d(
        [[1998, 7.4], [1999, 7.8], [2000, 7.7],
         [2001, 8.3], [2002, 8.0], [2003, 8.5]],
        Color = RGB::Red, PointsVisible = TRUE):
cars := plot::Polygon2d(
        [[1998, 3.2], [1999, 3.5], [2000, 3.7],
         [2001, 3.7], [2002, 4.0], [2003, 4.1]],
        Color = RGB::Blue,
                        PointsVisible = TRUE):
plot(plot::Scene2d(
  plot::CoordinateSystem2d(apples, ViewingBoxYRange = 0..10,
                           YAxisTitle = "apples/10^3 tons",
                           Axes = Origin, AxesOriginX = 1998,
                           XTicksNumber = None,
                           XTicksAt = [$ 1998..2003]),
  plot::CoordinateSystem2d(cars, ViewingBoxYRange = 0..5,
                           YAxisTitle = "cars/10^4",
                           Axes = Origin, AxesOriginX = 2003,
                           XTicksNumber = None,
                           XTicksAt = [$ 1998..2003])
)):

MuPAD graphics

Inside the coordinate systems, an arbitrary number of primitives (of the appropriate dimension) can be displayed. Thus, we always have a canvas, containing one or more scenes, with each scene containing one or more coordinate systems. The graphical primitives (or groups of such primitives) are contained in the coordinate systems. Hence, any MuPAD plot has the following general structure:


       Canvas
        |
        +-- Scene 1
        |    |
        |    +-- CoordinateSystem 1
        |    |    +-- Primitive 1
        |    |    +-- Primitive 2
        |    |    ...
        |    |
        |    +-- CoordinateSystem 2
        |    |    +-- Primitive
        |    |    ...
        |    ...
        |
        +-- Scene 2
        |    |
        |    +-- CoordinateSystem
        |    |    +-- Primitive
        |    |    ...
        |    ...
        ...

This is the “graphical tree” that is displayed by the “object browser” of the MuPAD graphics tool (see section Viewer, Browser, and Inspector: Interactive Manipulation).

Shortcuts: For simple plots containing primitives inside one coordinate system only that resides in a single scene of the canvas, it would be rather cumbersome to generate the picture by a command such as

plot(
  plot::Canvas(
    plot::Scene2d(
      plot::CoordinateSystem2d(Primitive1, Primitive2, ...)
    )
  )
):

In fact, the command

plot(Primitive1, Primitive2, ...):

suffices: It is a shurtcut of the above command. It generates automatically a coordinate system that contains the primitives, embedded it in a scene which is automatically placed inside a canvas object. Thus, this command implicitly creates the graphical tree


       Canvas
        |
        +-- Scene 1
             |
             +-- CoordinateSystem 1
                  +-- Primitive 1
                  +-- Primitive 2
                  ...

that becomes visible in the object browser.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS