plot .

“msharpmath”, The Simple is the Best

[100] 002 Tutorial plot                   plot

Click the above button for full-text tutorial of   ‘plot’ .

//==================================================================================
//   Umbrella ‘plot’  for drawing 2D figures
//==================================================================================
When character ‘+’ is attached to ‘plot’, plots are overlapped on the existing layout. In short,

plot   :  creates a new window
plot+ : use an existing window, if any

Similarly, holding window can be done by

.hold ;   // create a new window for holding
plot+.hold ;   // hold the current plot window

All the accumulated plots can be drawn by

plot ;  // plot now the stacked plots

In the below, <<opt>> means the option which can be omitted.
//————————————————————————————————————
// 2D curves
//————————————————————————————————————
plot .x[n=51,g=1](xa,xb) ( <<opt>>, f(x), … )         2D curve(s)
plot .t[n=51,g=1](ta,tb) ( <<opt>>, r(t), … ) .cyl    2D curve(s)

#> .hold;
#>   for.n(0,4) plot .x(0,15) ( .J_n(x) );
#> plot; // Bessel

results in a plot with 5 curves for the Bessel functions.

The Spoke ‘.cyl’ works as

x = r cos(t)
y = r sin(t)

with t as the angle parameter. Therefore,

#> plot .t(0,2*pi) ( 1 ) .cyl ;

draws a circle of radius 1.


//————————————————————————————————————
// 2D parametrized curve
//————————————————————————————————————
plot .@ u[n=51,g=1](ua,ub) ( <<opt>>, x(u),y(u) )       2D curve (single)
plot .@ u[n=51,g=1](ua,ub) ( <<opt>>, r(u),t(u) ) .cyl  2D curve (single)
#> plot .@ u(0,2*pi) ( 3*cos(t), 2*sin(t) ) ; // draws an ellipse

#> (a,b) = (12,5);;   // Epicycloid
#{
plot .@ t[1001](0,10*pi) (
<< u = (a/b+1)*t >>,      // make it easy
(a+b)*cos(t)-b*cos(u),
(a+b)*sin(t)-b*sin(u)
);
#}

#> plot.@ r[2001](-10,10) ( << t = r^2 >>, r*cos(t),r*sin(t) );   // when r < 0,  do not use .cyl (why? (-r)cos(t) != r cos(-t) )


//————————————————————————————————————
// 2D Phase Diagram
//————————————————————————————————————
plot .u[n=21,g=1](a,b) .v[n=21,g=1](c(u),d(u)) ( u’, v’ )
.phase[scale=1,headscale=1,headangle=30]

#> plot.y1[15](-5,5).y2[15](-3*cos(pi/11*y1),3*cos(pi/11*y1))
( y2,-sin(y1) ).phase[0.3,3];

//————————————————————————————————————
// Spokes in 2D geometry
//————————————————————————————————————
.flip                                 // (X,Y) = (y,x)          symmetry about line y = x
.xmove(a)                     // (X,Y) = (x+a,y)        translate in x-direction by a
.ymove(b)                     // (X,Y) = (x,y+b)        translate in y-direction by b
.move(a,b)                    // (X,Y) = (x+a,y+b)      translate by a vector (a,b)
.xscale(sx,a=0)             // (X,Y) = (a+sx*(x-a),y) elongate in x-dir about line x=a
.yscale(sy,b=0)             // (X,Y) = (x,b+sy*(y-b)) elongate in y-dir about line y=b
.xlog                               // (X,Y) = (log10(x), y)
.ylog                               // (X,Y) = (x, log10(y))
.xylog/loglog                 // (X,Y) = (log10(x), log10(y))
.xsym(a=0)                   // (X,Y) = (2*a-x, y)       symmetry about line x=a
.ysym(b=0)                   // (X,Y) = (x, 2*b-y)       symmetry about line y=b
.osym         @(xo,yo)    // (X,Y) = (2*xo-x, 2*yo-y) symmetry about point (xo,yo)
.scale(sx,sy) @(xo,yo) // (X,Y) = (xo+sx*(x-xo),yo+sy*(y-yo))
.zrot(t)      @(xo,yo)    // rotate counterclockwise about (xo,yo)
.lsym(a,b,c)                  // symmetry with respect to line ax+by+c = 0
.lstep                             // lower-step function
.ustep                            // upper-step function
.xstem                          // stem with respect to the x-coordinate
.ystem                          // stem with respect to the y-coordinate
.xystem                        // stem with respect to the x- and y-coordinates
.stem                             // stem with circle
.link                               // connect piecewise curve to the last curve
.merge                           // make all curves to be a single curve
.movelink                      // connect piecewise curves to the last ending point
.copy[n] (dx,dy)           // duplicate a total of n curves and move by (dx,dy)
.copylink[n] (dx,dy)    // copy[n](dx,dy) and make all curves to be a single curve

.xmean(xm)               // extracts a mean value of x
.ymean(ym)               // extracts a mean value of y
.togo(A)                       // extracts matrix A for vertex data of each curve
.allout(A)                     // extracts matrix A for all the vertex data
.info                              // print out information on curves and vertex

//————————————————————————————————————
// built-in 2D geometry
//————————————————————————————————————
.triangle  (a,b,c      )
.square    (a          )
.star      (r          )
.rectangle (a,b        )
.parallel  (a,b, theta )
.trapezoid (a,b, height)

.circle  [nt=51,gt=1] (radius)
.polygon [nvert,gt=1] (radius) // nvert >= 3
.ellipse [nt=51,gt=1] (a,b   )

.point  (xo,yo)
.vector [scale=1,headscale=1,headangle=30] (a,b)
.line   (x1,y1, x2,y2)

 

//————————————————————————————————————

Comments are closed.