Skip to Main Content Skip to Search
Product Documentation

plot::PointList2dfinite lists of 2D points

plot::PointList3dfinite lists of 3D points

plot::PointList2d and plot::PointList3d hold lists of points in 2D or 3D.

→ Examples

Calls:

plot::PointList2d(pts, <a = amin .. amax>, Options)

plot::PointList3d(pts, <a = amin .. amax>, Options)

plot::PointList2d(`M_{2d}`, <a = amin .. amax>, Options)

plot::PointList3d(`M_{3d}`, <a = amin .. amax>, Options)

Parameters:

pts

A list of points. A point must not be of type plot::Point2d or plot::Point3d, respectively. In 2D, each point must be a list of two real-valued expressions (the coordinates) and an optional RGB color. In 3D, each point mut be a list of three expressions (the coordinates) and an optional RGB or RGBa color. The lists specifying the points and the colors must all have the same length. 
pts is equivalent to the attributes Points2d, Points3d.

`M_{2d}`

An array or a matrix with 2 columns. Each row provides the coordinates of one point.   
`M_{2d}` is equivalent to the attribute Points2d.

`M_{3d}`

An array or a matrix with 3 columns. Each row provides the coordinates of one point.   
`M_{3d}` is equivalent to the attribute Points3d.

See Also:

plot, plot::copy, plot::Listplot, plot::Point2d, plot::Point3d, plot::Polygon2d, plot::Polygon3d, plot::Scatterplot

Details:

Example 1

plot::PointList3d provides a basic form of scatter plot:  

plot(plot::PointList3d([[1,1,1], [1,2,2], [1,3,2], [1,3,4],
                        [2,1,1], [2,2,3], [2,3.5, 4]],
                       PointSize=5))

MuPAD graphics

We can use this, for example, to get a visual test of random number generators:

r := frandom(0):
plot(plot::PointList3d([[r(), r(), r()] $ i=1..10000])):

MuPAD graphics

r := random(10^10)*1e-10:
plot(plot::PointList3d([[r(), r(), r()] $ i=1..10000])):

MuPAD graphics

frandom and random fill the cube nicely, without noticeable patterns. The following generator, however, should probably not be used:

randseed := 12345:
r := proc()
     begin
       randseed := (randseed * 17 + 8) mod 10^10:
       1e-10 * randseed;
     end:
plot(plot::PointList3d([[r(), r(), r()] $ i=1..10000])):

MuPAD graphics

Example 2

The following iteration leads to the so-called Hénon attractor (from chaos theory):

c1 := 1.4:
c2 := 0.3:
henon_iter := (x, y) -> [c1*x^2+y-1, c2*x]:

We start at (0, 0), let hundred iteration cycles pass by (to only plot the attractor) and then collect the next three thousand points:

[x, y] := [0, 0]:
for i from 1 to 100 do
  [x, y] := henon_iter(x, y);
end_for:
data := {}:
for i from 1 to 3000 do
  [x, y] := henon_iter(x, y);
  data := data union {[x, y]};
end_for:

Note that we collected the data in a set, because adding elements to a set is a fast operation, unlike changing the length of a list, and we don't care for the order in which points were reached. To plot the data, we must convert it to a list first:

data := coerce(data, DOM_LIST):
plot(plot::PointList2d(data))

MuPAD graphics

We'd like to invite you to experiment with different values of c1 and c2 and see how they change the resulting image.

Example 3

plot::PointList2d and plot::PointList3d allow you to specify the colors of the points. For example, the following list contains two points. When you plot this list, the first point appears in red, and the second point appears in green:

Coords := [[3, 4, RGB::Red], [5, 5, RGB::Green]];
plotCoords := plot::PointList2d(Coords):
plot(plotCoords,  PointSize=5)

[[3, 4, [1.0, 0.0, 0.0]], [5, 5, [0.0, 1.0, 0.0]]]
MuPAD graphics

If you specify the color of one point, you must also specify the colors of all other points in the list:

Coords := [[3, 4, RGB::Red], [5, 5]];
plotCoords := plot::PointList2d(Coords)

[[3, 4, [1.0, 0.0, 0.0]], [5, 5]]
Error: expecting a list of lists of 2 expressions and an optional color value for attribute 'Points2d' in PointList2d object [plot]

Example 4

(Feigenbaum's period doubling route to chaos)

We consider the iteration x[n + 1] = f[p](x[n]) where funcDecl(f[p], x, p*x*(1 - x)) is the “logistic map” with a parameter p. The iteration map f[p] maps the interval [0, 1] to itself for (0 <= p) <= 4. For small values of p, the sequence (x[n]) has a finite number of accumulation points that are visited cyclically. Increasing p, the accumulation points split into 2 separate accumulation points for certain critical values of p (“period doubling”). For _approx(p, 3.569945672Symbol::dots), there are infinitely many accumulation points and the sequence (x[n]) behaves chaotically.

We wish to visualize the accumulation points as functions of p (“Feigenbaum diagram”).

For P closely spaced values of p, we construct the sequence (x[n]) starting with x[0] = 0.5. We ignore the first N values, expecting that the next M values cycle over the accumulation points. These points are added to a list plotdata that is finally fed into a PointList2d for plotting:

f:= (p, x) -> p*x*(1-x):

P:= 500: // number of steps in p direction
N:= 200: // transitional steps before we are close to the cycle
M:= 300: // maximal number of points on the cycle

pmin:= 2.8: // Consider p between
pmax:= 4.0: // pmin and pmax
plotdata:= [ ]:
for p in [pmin + i*(pmax - pmin)/P $ i = 0..P] do
    // First, do N iterations to drive the
    // point x towards the limit cycle
    x:= 0.5:
    for i from 1 to N do
      x:= f(p, x):
    end_for:

     // consider the next M iterates and use them as plot data:
    xSequence:= table():
    xSequence[1]:= x;
    for i from 2 to M do
        x:= f(p, x):
        if abs(x - xSequence[1]) < 10^(-5) then
           // We are back at the beginning of the cycle;
           // the points will repeat. Go to the next p.
           break;
        else
           xSequence[i]:= x;
        end_if;
    end_for:
    plotdata:= plotdata . [[p, rhs(x)] $ x in xSequence];
end_for:

plot(plot::PointList2d(plotdata,
                       PointColor = RGB::Black,
                       PointSize = 0.5*unit::mm)):

MuPAD graphics

 

delete f, P, N, M, pmin, pmax, plotdata, x, xSequence, i;

 

  


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